Bird
0
0

Given this code snippet, what posts will be displayed?

medium📝 component behavior Q13 of 15
Wordpress - Custom Theme Development
Given this code snippet, what posts will be displayed?
$custom_query = new WP_Query(['category_name' => 'news', 'posts_per_page' => 2]);
if ($custom_query->have_posts()) :
  while ($custom_query->have_posts()) : $custom_query->the_post();
    the_title();
  endwhile;
endif;
wp_reset_postdata();
AOnly posts from the default query ignoring 'news'
BAll posts from the 'news' category
COnly the first 2 posts from the 'news' category
DNo posts will be displayed due to syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze WP_Query parameters

    The query requests posts from category 'news' and limits to 2 posts.
  2. Step 2: Understand the loop behavior

    The loop runs through posts found by $custom_query, showing only those 2 posts.
  3. Final Answer:

    Only the first 2 posts from the 'news' category -> Option C
  4. Quick Check:

    WP_Query limits posts = A [OK]
Quick Trick: posts_per_page limits how many posts show [OK]
Common Mistakes:
  • Assuming all posts show ignoring posts_per_page
  • Confusing default query with custom query
  • Missing wp_reset_postdata() after custom loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes