Bird
0
0

You want to optimize a query to fetch only published posts from the 'events' category, limited to 4 posts, ordered by date descending. Which is the best WP_Query argument array?

hard📝 Application Q15 of 15
Wordpress - WordPress Query and Database
You want to optimize a query to fetch only published posts from the 'events' category, limited to 4 posts, ordered by date descending. Which is the best WP_Query argument array?
A{'category_name' => 'events', 'posts_per_page' => 4, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC'}
B{'category' => 'events', 'limit' => 4, 'status' => 'published', 'order_by' => 'date', 'order' => 'desc'}
C{'cat_name' => 'events', 'posts_per_page' => 4, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'ASC'}
D{'category_name' => 'events', 'posts_per_page' => 10, 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'DESC'}
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct category parameter

    'category_name' is the correct parameter to filter by category slug.
  2. Step 2: Check post limit and status

    'posts_per_page' => 4 limits posts; 'post_status' => 'publish' fetches only published posts.
  3. Step 3: Verify ordering parameters

    'orderby' => 'date' and 'order' => 'DESC' correctly order posts by newest first.
  4. Final Answer:

    {'category_name' => 'events', 'posts_per_page' => 4, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC'} -> Option A
  5. Quick Check:

    Correct params + limit + order = {'category_name' => 'events', 'posts_per_page' => 4, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC'} [OK]
Quick Trick: Use exact WP_Query keys: category_name, posts_per_page, post_status, orderby [OK]
Common Mistakes:
  • Using wrong parameter names like 'category' or 'limit'
  • Mixing 'order' case sensitivity
  • Setting wrong order direction or post status

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes