Bird
0
0

You want to display a list of posts excluding category 'news' and showing only posts with the custom field 'featured' set to 'yes'. Which WP_Query arguments correctly achieve this?

hard📝 state output Q15 of 15
Wordpress - Custom Theme Development
You want to display a list of posts excluding category 'news' and showing only posts with the custom field 'featured' set to 'yes'. Which WP_Query arguments correctly achieve this?
A<code>['category__not_in' => get_cat_ID('news'), 'meta_key' => 'featured', 'meta_value' => 'yes']</code>
B<code>['cat' => '-'.get_cat_ID('news'), 'meta_query' => [['key' => 'featured', 'value' => 'yes']]]</code>
C<code>['category_name' => 'news', 'meta_key' => 'featured', 'meta_value' => 'yes']</code>
D<code>['category__in' => [get_cat_ID('news')], 'meta_key' => 'featured', 'meta_value' => 'yes']</code>
Step-by-Step Solution
Solution:
  1. Step 1: Exclude category 'news'

    Using 'cat' => '-ID' excludes a category by its ID. get_cat_ID('news') gets the ID.
  2. Step 2: Filter posts with custom field 'featured' = 'yes'

    Use meta_query with key and value to filter posts by custom fields.
  3. Step 3: Combine both conditions correctly

    ['cat' => '-'.get_cat_ID('news'), 'meta_query' => [['key' => 'featured', 'value' => 'yes']]] uses negative cat ID and meta_query array properly.
  4. Final Answer:

    ['cat' => '-'.get_cat_ID('news'), 'meta_query' => [['key' => 'featured', 'value' => 'yes']]] -> Option B
  5. Quick Check:

    Exclude category with negative ID + meta_query = C [OK]
Quick Trick: Use negative cat ID to exclude categories in WP_Query [OK]
Common Mistakes:
  • Using category__not_in without meta_query for custom fields
  • Including category instead of excluding
  • Using meta_key/meta_value without meta_query array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes