The WordPress PHP class WP_Query is a set of instructions that allows you to customize the display of one or more posts based on defined criteria. It's used to extract specific elements from the site based on predefined criteria such as categories, tags, authors, dates, content types, and more.
To use the WP_Query class, you create a query specifying the criteria for retrieving the data. For example, you can define the categories, tags, the number of posts to display, etc. This query can be integrated in various ways: directly into the template using PHP, via query blocks with Gutenberg, by adding dynamic data with custom PHP code, using plugins like Divifilter's Blog module with Divi, using Oxygen Builder's Query Builder, or using widgets like Pots and Loop Grid with Elementor.
An example of using the WP_Query class is as follows:
```php
$args = array(
'post_type' => 'post',
'category_name' => 'actualites',
'posts_per_page' => 5
);
$query = new WP_Query( $args );
if ($query->have_posts() ) {
while ($query->have_posts() ) {
$query->the_post();
/ The code to display the post content goes here
}
}
wp_reset_postdata();
?>
```
A commonly used synonym to describe this process is "query loop." For more information, you can consult the associated documentation.