Challenge - 5 Problems
Tax and Meta Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What posts are returned by this tax query?
Consider this WordPress query snippet. Which posts will it return based on the tax query?
Wordpress
<?php $args = [ 'post_type' => 'product', 'tax_query' => [ [ 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => ['electronics', 'appliances'], 'operator' => 'AND' ] ] ]; $query = new WP_Query($args); ?>
Attempts:
2 left
💡 Hint
The 'operator' key controls how terms are combined in tax queries.
✗ Incorrect
The 'operator' => 'AND' means posts must have all listed terms. So only posts assigned to both 'electronics' and 'appliances' categories are returned.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this meta query
Which option correctly fixes the syntax error in this meta query array?
Wordpress
<?php $args = [ 'post_type' => 'post', 'meta_query' => [ 'relation' => 'OR', [ 'key' => 'price', 'value' => 100, 'compare' => '>' ], [ 'key' => 'stock', 'value' => 0, 'compare' => '>=' ] ] ]; $query = new WP_Query($args); ?>
Attempts:
2 left
💡 Hint
Check array syntax carefully, especially commas between elements.
✗ Incorrect
The 'relation' key must be separated by a comma from the next array element. Missing comma causes syntax error.
❓ state_output
advanced2:00remaining
What is the value of $count after this meta query?
Given this code, what is the value of $count after running the query?
Wordpress
<?php $args = [ 'post_type' => 'event', 'meta_query' => [ [ 'key' => 'event_date', 'value' => date('Y-m-d'), 'compare' => '>=', 'type' => 'DATE' ] ] ]; $query = new WP_Query($args); $count = $query->found_posts; ?>
Attempts:
2 left
💡 Hint
The meta query filters posts by date compared to today.
✗ Incorrect
The meta query filters events where 'event_date' is today or later. 'found_posts' gives count of matching posts.
🔧 Debug
advanced2:00remaining
Why does this tax query return no posts?
This tax query returns no posts even though posts exist in the 'news' category. What is the cause?
Wordpress
<?php $args = [ 'post_type' => 'post', 'tax_query' => [ [ 'taxonomy' => 'category', 'field' => 'name', 'terms' => 'news' ] ] ]; $query = new WP_Query($args); ?>
Attempts:
2 left
💡 Hint
Check the data type of 'terms' in tax queries.
✗ Incorrect
The 'terms' parameter must be an array even if only one term is used. Passing a string causes no matches.
🧠 Conceptual
expert2:00remaining
How does combining tax_query and meta_query affect results?
If a WP_Query uses both 'tax_query' and 'meta_query' arrays, how are the results filtered?
Attempts:
2 left
💡 Hint
Think about how multiple query parameters combine in WP_Query.
✗ Incorrect
WP_Query combines tax_query and meta_query with AND logic, so posts must satisfy both to be included.