Bird
0
0

Which of the following is the correct syntax to query posts with a meta key 'color' equal to 'blue' using WP_Query?

easy📝 Syntax Q3 of 15
Wordpress - WordPress Query and Database
Which of the following is the correct syntax to query posts with a meta key 'color' equal to 'blue' using WP_Query?
Anew WP_Query(['meta_query' => ['key' => 'color', 'value' => 'blue']])
Bnew WP_Query(['meta_key' => 'blue', 'meta_value' => 'color'])
Cnew WP_Query(['meta_key' => 'color', 'meta_value' => 'blue'])
Dnew WP_Query(['meta_query' => ['meta_key' => 'color', 'meta_value' => 'blue']])
Step-by-Step Solution
Solution:
  1. Step 1: Recall WP_Query meta key syntax

    Use 'meta_key' and 'meta_value' keys for simple meta queries.
  2. Step 2: Check each option's correctness

    new WP_Query(['meta_key' => 'color', 'meta_value' => 'blue']) correctly pairs 'meta_key' with 'color' and 'meta_value' with 'blue'.
  3. Final Answer:

    new WP_Query(['meta_key' => 'color', 'meta_value' => 'blue']) -> Option C
  4. Quick Check:

    Correct meta key syntax = new WP_Query(['meta_key' => 'color', 'meta_value' => 'blue']) [OK]
Quick Trick: Use meta_key and meta_value for simple meta queries [OK]
Common Mistakes:
  • Swapping meta_key and meta_value
  • Using meta_query without proper array keys
  • Confusing meta_key with meta_query keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes