Consider this WordPress code querying a custom post type 'book'. What does echo $query->found_posts; output?
<?php $args = [ 'post_type' => 'book', 'posts_per_page' => 5, 'post_status' => 'publish' ]; $query = new WP_Query($args); echo $query->found_posts; ?>
Think about what found_posts means in WP_Query.
found_posts gives the total count of posts matching the query, ignoring pagination limits like posts_per_page. So it shows how many 'book' posts are published in total.
Given this WP_Query for 'movie' post type with a meta_query filtering by 'rating' > 7, what posts are returned?
<?php $args = [ 'post_type' => 'movie', 'meta_query' => [ [ 'key' => 'rating', 'value' => 7, 'compare' => '>', 'type' => 'NUMERIC' ] ] ]; $query = new WP_Query($args); ?>
Remember that 'post_type' limits the query to that type, and 'meta_query' filters by meta fields.
The query returns posts of type 'movie' that have a meta field 'rating' with a numeric value greater than 7. Other posts or those with lower ratings are excluded.
Choose the correct argument array to query 'event' custom post type ordered by 'event_date' meta key ascending.
Ordering by a numeric custom field requires specific keys.
To order by a numeric meta field, use 'meta_key' with 'orderby' set to 'meta_value_num' and 'order' ascending or descending as needed.
Examine this code snippet. Why does it return zero posts?
<?php $args = [ 'post_type' => 'product', 'tax_query' => [ [ 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'electronics' ] ], 'posts_per_page' => 10 ]; $query = new WP_Query($args); ?>
Check if the term slug exists in the taxonomy.
If the term slug 'electronics' does not exist in the 'product_cat' taxonomy, the query returns no posts. The other parts are valid.
In a WP_Query for a custom post type, what does setting 'suppress_filters' => false do?
Think about how WordPress filters interact with queries.
Setting 'suppress_filters' to false allows WordPress filters to run on the query SQL, enabling plugins or themes to modify the query. The default true suppresses these filters.