Bird
0
0

You want to display posts that belong to category ID 4 or category ID 7 using WP_Query. Which query parameter array will correctly achieve this?

hard📝 Application Q15 of 15
Wordpress - WordPress Query and Database
You want to display posts that belong to category ID 4 or category ID 7 using WP_Query. Which query parameter array will correctly achieve this?
Aarray('category_name' => '4,7')
Barray('cat' => '4,7')
Carray('category__in' => array(4, 7))
Darray('cat' => array(4, 7))
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to query multiple categories

    To query posts in multiple categories by ID, use 'category__in' with an array of IDs.
  2. Step 2: Evaluate each option

    array('cat' => '4,7') uses a string with comma which is invalid for 'cat'. array('category_name' => '4,7') uses 'category_name' with numbers which expects slugs. array('cat' => array(4, 7)) uses 'cat' with an array which is invalid.
  3. Final Answer:

    array('category__in' => array(4, 7)) -> Option C
  4. Quick Check:

    Multiple category IDs use 'category__in' with array = A [OK]
Quick Trick: Use 'category__in' with array for multiple category IDs [OK]
Common Mistakes:
  • Passing multiple IDs as comma string to 'cat'
  • Using 'category_name' with numeric IDs
  • Passing array to 'cat' which expects single ID

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes