0
0
Wordpressframework~20 mins

Why custom queries retrieve specific data in Wordpress - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Query Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does WP_Query filter posts by category?
Given a WP_Query with 'category_name' set, what posts will it retrieve?
Wordpress
<?php
$query = new WP_Query(['category_name' => 'news']);
while ($query->have_posts()) {
  $query->the_post();
  the_title();
}
?>
AAll posts regardless of category
BPosts assigned to categories with names containing 'news' as substring
CPosts assigned to the 'news' category only
DPosts assigned to any category except 'news'
Attempts:
2 left
💡 Hint
Think about how 'category_name' parameter works in WP_Query.
📝 Syntax
intermediate
2:00remaining
Correct syntax for meta_query in WP_Query
Which option correctly retrieves posts where meta key 'color' equals 'blue'?
Wordpress
<?php
$args = [
  'meta_query' => [
    // Fill here
  ]
];
$query = new WP_Query($args);
?>
A['color' => 'blue']
B[['key' => 'color', 'value' => 'blue', 'compare' => '=']]
C[['meta_key' => 'color', 'meta_value' => 'blue']]
D[['key' => 'color', 'value' => ['blue'], 'compare' => 'IN']]
Attempts:
2 left
💡 Hint
meta_query expects an array of arrays with keys 'key', 'value', and 'compare'.
🔧 Debug
advanced
2:00remaining
Why does this custom query return no posts?
This WP_Query returns no posts. What is the cause?
Wordpress
<?php
$args = [
  'post_type' => 'product',
  'category_name' => 'electronics'
];
$query = new WP_Query($args);
?>
A'category_name' does not filter custom post types unless taxonomy is registered for them
BThe 'post_type' value 'product' is invalid and causes no results
CThe 'category_name' parameter must be 'category' not 'category_name'
DWP_Query cannot filter by category and post_type simultaneously
Attempts:
2 left
💡 Hint
Think about how categories relate to custom post types.
state_output
advanced
2:00remaining
What posts does this complex WP_Query return?
Analyze the query and select the correct description of posts retrieved.
Wordpress
<?php
$args = [
  'post_type' => 'post',
  'meta_query' => [
    'relation' => 'OR',
    ['key' => 'color', 'value' => 'red', 'compare' => '='],
    ['key' => 'size', 'value' => 'large', 'compare' => '=']
  ],
  'category_name' => 'sale'
];
$query = new WP_Query($args);
?>
APosts in 'sale' category with meta 'color'='red' OR meta 'size'='large'
BPosts with meta 'color'='red' OR meta 'size'='large' regardless of category
CPosts in 'sale' category with both meta 'color'='red' AND meta 'size'='large'
DPosts in 'sale' category regardless of meta values
Attempts:
2 left
💡 Hint
Meta queries combine with 'relation' inside meta_query, category_name filters posts by category.
🧠 Conceptual
expert
2:00remaining
Why does WP_Query ignore 'posts_per_page' in some custom queries?
In some custom WP_Query calls, setting 'posts_per_page' has no effect. What is the most likely reason?
A'posts_per_page' only works with default post type 'post'
B'posts_per_page' must be set before 'post_type' to work
CThe 'paged' parameter must be set to enable 'posts_per_page'
DThe query uses 'nopaging' => true which overrides 'posts_per_page'
Attempts:
2 left
💡 Hint
Check if any parameter disables pagination.