Challenge - 5 Problems
Query Parameters Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
How does WP_Query handle multiple query parameters?
Consider the following WP_Query arguments:
What will be the result of this query?
array('post_type' => 'post', 'category_name' => 'news', 'posts_per_page' => 5)What will be the result of this query?
Attempts:
2 left
💡 Hint
Think about how WP_Query filters posts by category and limits the number of posts.
✗ Incorrect
The query filters posts by the 'news' category and limits the results to 5 posts because 'posts_per_page' is set to 5.
📝 Syntax
intermediate2:00remaining
Identify the correct syntax for querying posts by meta key and value
Which of the following WP_Query arguments correctly queries posts where the meta key 'color' equals 'blue'?
Attempts:
2 left
💡 Hint
WP_Query uses 'meta_query' as an array of conditions for meta filtering.
✗ Incorrect
The correct way to query by meta key and value is using 'meta_query' with an array specifying 'key' and 'value'.
🔧 Debug
advanced2:00remaining
Why does this WP_Query return no posts?
Given this code:
Why might this query return no posts even if products exist in the 'electronics' category?
$args = array('post_type' => 'product', 'category_name' => 'electronics');
$query = new WP_Query($args);Why might this query return no posts even if products exist in the 'electronics' category?
Attempts:
2 left
💡 Hint
Think about default taxonomies and custom post types.
✗ Incorrect
'category_name' filters the default 'category' taxonomy which is linked only to the 'post' post type. Custom post types like 'product' usually use custom taxonomies.
🧠 Conceptual
advanced2:00remaining
How does 'paged' parameter affect WP_Query results?
If you set 'posts_per_page' to 3 and 'paged' to 2 in WP_Query arguments, what will the query return?
Attempts:
2 left
💡 Hint
Consider how pagination works in WordPress queries.
✗ Incorrect
'paged' specifies the page number of results. With 'posts_per_page' set to 3 and 'paged' to 2, the query returns posts 4 to 6.
❓ state_output
expert2:00remaining
What is the value of $query->found_posts after this WP_Query?
Given the code:
Assuming there are 7 posts in the 'news' category, what will be output?
$args = array('post_type' => 'post', 'posts_per_page' => 2, 'category_name' => 'news');
$query = new WP_Query($args);
echo $query->found_posts;Assuming there are 7 posts in the 'news' category, what will be output?
Attempts:
2 left
💡 Hint
Look up what 'found_posts' property represents in WP_Query.
✗ Incorrect
'found_posts' holds the total number of posts matching the query ignoring pagination limits.