Bird
0
0

Identify the issue in this custom query:

medium📝 Debug Q6 of 15
Wordpress - WordPress Query and Database
Identify the issue in this custom query:
$args = ['cat' => 'news'];
$query = new WP_Query($args);
A'cat' is deprecated and should not be used
B'cat' should be replaced with 'category_name' for IDs
C'cat' expects a category ID, not a slug
DThere is no issue; the query is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand 'cat' parameter

    The 'cat' parameter requires a category ID (integer), not a slug string.
  2. Step 2: Correct usage

    To query by category slug, use 'category_name' => 'news'.
  3. Final Answer:

    'cat' expects a category ID, not a slug -> Option C
  4. Quick Check:

    'cat' needs numeric ID, not slug [OK]
Quick Trick: 'cat' requires ID; use 'category_name' for slugs [OK]
Common Mistakes:
  • Passing category slug to 'cat' parameter
  • Confusing 'cat' with 'category_name'
  • Assuming 'cat' accepts strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes