Bird
0
0

What will the following tax_query return?

medium📝 Predict Output Q4 of 15
Wordpress - WordPress Query and Database
What will the following tax_query return?
array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => ['news', 'updates'],
'operator' => 'IN'
),
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => ['featured'],
'operator' => 'NOT IN'
)
)
APosts in categories 'news' or 'updates' and tagged 'featured'
BPosts in categories 'news' or 'updates' but NOT tagged 'featured'
CPosts tagged 'featured' but NOT in categories 'news' or 'updates'
DPosts in any category or tag
Step-by-Step Solution
Solution:
  1. Step 1: Analyze first tax_query array

    Filters posts in categories with slug 'news' or 'updates' using 'IN' operator.
  2. Step 2: Analyze second tax_query array

    Excludes posts tagged with slug 'featured' using 'NOT IN' operator.
  3. Step 3: Relation 'AND' combines both filters

    Posts must match both conditions: in categories and not tagged 'featured'.
  4. Final Answer:

    Posts in categories 'news' or 'updates' but NOT tagged 'featured' -> Option B
  5. Quick Check:

    tax_query with AND and NOT IN excludes 'featured' tags [OK]
Quick Trick: 'NOT IN' excludes terms; 'AND' requires all conditions [OK]
Common Mistakes:
  • Ignoring 'NOT IN' operator effect
  • Confusing 'AND' with 'OR' relation
  • Assuming tags must be included

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes