Bird
0
0

You want to query posts that are either in category 4 or tagged with 'featured'. Which WP_Query argument setup achieves this?

hard📝 component behavior Q8 of 15
Wordpress - WordPress Query and Database
You want to query posts that are either in category 4 or tagged with 'featured'. Which WP_Query argument setup achieves this?
A[{'taxonomy': 'category', 'field': 'term_id', 'terms': [4], 'operator': 'IN'}, {'taxonomy': 'post_tag', 'field': 'slug', 'terms': ['featured'], 'operator': 'IN'}], 'relation' => 'OR'
B['category_name' => '4', 'tag_slug__in' => ['featured']]
C['category__in' => [4], 'tag' => 'featured']
D['cat' => 4, 'tag' => 'featured', 'relation' => 'OR']
Step-by-Step Solution
Solution:
  1. Step 1: Understand combining category and tag with OR

    WP_Query requires 'tax_query' with 'relation' => 'OR' to combine taxonomies with OR logic.
  2. Step 2: Analyze each option

    Only [{'taxonomy': 'category', 'field': 'term_id', 'terms': [4], 'operator': 'IN'}, {'taxonomy': 'post_tag', 'field': 'slug', 'terms': ['featured'], 'operator': 'IN'}], 'relation' => 'OR' correctly uses 'tax_query' with two taxonomy arrays and 'relation' => 'OR'.
  3. Final Answer:

    Use tax_query with relation 'OR' combining category and tag -> Option A
  4. Quick Check:

    Use tax_query with 'relation' => 'OR' for multiple taxonomies [OK]
Quick Trick: Use tax_query with 'relation' => 'OR' to combine categories and tags [OK]
Common Mistakes:
  • Using 'cat' and 'tag' together without tax_query for OR logic
  • Confusing category IDs with slugs
  • Misusing 'relation' outside tax_query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes