Bird
0
0

Identify the error in this WP_Query code snippet:

medium📝 Debug Q14 of 15
Wordpress - WordPress Query and Database
Identify the error in this WP_Query code snippet:
 $args = array('post_per_page' => 10, 'category_name' => 'updates'); $query = new WP_Query($args); 
AThe 'category' parameter should be 'category_name'.
BThe parameter 'post_per_page' is misspelled; should be 'posts_per_page'.
CWP_Query cannot accept arrays as arguments.
DThere is no error; the code is correct.
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter names for limiting posts

    The correct parameter is 'posts_per_page', not 'post_per_page'.
  2. Step 2: Verify category parameter

    The parameter 'category_name' => 'updates' uses the correct syntax for category slug.
  3. Final Answer:

    The parameter 'post_per_page' is misspelled; should be 'posts_per_page'. -> Option B
  4. Quick Check:

    Correct parameter spelling = posts_per_page [OK]
Quick Trick: Check spelling of WP_Query parameters carefully [OK]
Common Mistakes:
  • Using 'post_per_page' instead of 'posts_per_page'
  • Confusing 'category' with 'category_name'
  • Assuming WP_Query doesn't accept arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes