Bird
0
0

Identify the error in this query:

medium📝 Debug Q6 of 15
Wordpress - WordPress Query and Database
Identify the error in this query:
$args = array('cat' => '5', 'posts_per_page' => 'ten');
$query = new WP_Query($args);
A'cat' should be category slug, not ID
B'posts_per_page' cannot be used with 'cat'
C'cat' parameter is invalid, use 'category_name'
D'posts_per_page' should be an integer, not a string
Step-by-Step Solution
Solution:
  1. Step 1: Check 'cat' parameter usage

    'cat' expects a category ID as integer or string number, so '5' is valid.
  2. Step 2: Validate 'posts_per_page' value

    'posts_per_page' must be an integer, but 'ten' is a string word, causing error.
  3. Final Answer:

    'posts_per_page' should be an integer, not a string -> Option D
  4. Quick Check:

    posts_per_page = integer required [OK]
Quick Trick: Use integers for posts_per_page, not words [OK]
Common Mistakes:
  • Using category slug with 'cat' parameter
  • Passing string words instead of numbers
  • Thinking posts_per_page conflicts with cat

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes