0
0
Wordpressframework~20 mins

Query parameters in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Query Parameters Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does WP_Query handle multiple query parameters?
Consider the following WP_Query arguments:
array('post_type' => 'post', 'category_name' => 'news', 'posts_per_page' => 5)

What will be the result of this query?
AReturns posts of any type limited to 5 posts.
BReturns 5 posts from all categories ignoring 'category_name'.
CReturns the latest 5 posts from the 'news' category only.
DReturns all posts from the 'news' category ignoring 'posts_per_page'.
Attempts:
2 left
💡 Hint
Think about how WP_Query filters posts by category and limits the number of posts.
📝 Syntax
intermediate
2: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'?
Aarray('meta_query' => array('color' => 'blue'))
Barray('meta_key' => 'color', 'meta_compare' => '=', 'meta_value' => 'blue')
Carray('meta_key' => 'color', 'meta_value' => 'blue')
Darray('meta_query' => array(array('key' => 'color', 'value' => 'blue')))
Attempts:
2 left
💡 Hint
WP_Query uses 'meta_query' as an array of conditions for meta filtering.
🔧 Debug
advanced
2:00remaining
Why does this WP_Query return no posts?
Given this code:
$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?
ABecause 'post_type' should be 'products' plural to match the taxonomy.
BBecause 'category_name' only works with the 'post' post type, not 'product'.
CBecause 'category_name' requires a taxonomy parameter to be set explicitly.
DBecause WP_Query does not support filtering by category.
Attempts:
2 left
💡 Hint
Think about default taxonomies and custom post types.
🧠 Conceptual
advanced
2: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?
AThe first 3 posts from the second page of results (posts 4 to 6).
BThe first 6 posts from the first page.
CAll posts ignoring pagination.
DAn error because 'paged' cannot be used with 'posts_per_page'.
Attempts:
2 left
💡 Hint
Consider how pagination works in WordPress queries.
state_output
expert
2:00remaining
What is the value of $query->found_posts after this WP_Query?
Given the code:
$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?
A7
B2
C5
D0
Attempts:
2 left
💡 Hint
Look up what 'found_posts' property represents in WP_Query.