Bird
0
0

Which of the following is the correct syntax to filter posts with a meta key 'price' greater than 100 using meta_query?

easy📝 Syntax Q3 of 15
Wordpress - WordPress Query and Database
Which of the following is the correct syntax to filter posts with a meta key 'price' greater than 100 using meta_query?
A'meta_query' => [['key' => 'price', 'value' => 100, 'compare' => '>', 'type' => 'NUMERIC']]
B'meta_query' => [['key' => 'price', 'value' => '100', 'compare' => '<', 'type' => 'CHAR']]
C'meta_query' => [['key' => 'price', 'value' => 100, 'compare' => '=', 'type' => 'NUMERIC']]
D'meta_query' => [['key' => 'price', 'value' => 100]]
Step-by-Step Solution
Solution:
  1. Step 1: Understand meta_query comparison

    To filter numeric values greater than 100, use 'compare' => '>' and 'type' => 'NUMERIC'.
  2. Step 2: Check syntax correctness

    'meta_query' => [['key' => 'price', 'value' => 100, 'compare' => '>', 'type' => 'NUMERIC']] correctly uses 'key', 'value', 'compare', and 'type' with proper values.
  3. Final Answer:

    Correct meta_query syntax with '>' and NUMERIC type -> Option A
  4. Quick Check:

    meta_query numeric comparison = 'meta_query' => [['key' => 'price', 'value' => 100, 'compare' => '>', 'type' => 'NUMERIC']] [OK]
Quick Trick: Use 'compare' and 'type' for numeric meta_query filters [OK]
Common Mistakes:
  • Omitting 'type' for numeric comparison
  • Using wrong comparison operator
  • Passing numeric value as string without type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes