Bird
0
0

Which of the following is the correct syntax to create a custom query in WordPress?

easy📝 Syntax Q3 of 15
Wordpress - WordPress Query and Database
Which of the following is the correct syntax to create a custom query in WordPress?
A$query = new WP_Query('category_name' = 'news');
B$query = WP_Query('category_name' => 'news');
C$query = new WP_Query(['category_name' => 'news']);
D$query = WP_Query(['category_name' => 'news']);
Step-by-Step Solution
Solution:
  1. Step 1: Check WP_Query instantiation syntax

    WP_Query must be instantiated with 'new' and an array of arguments.
  2. Step 2: Validate array syntax

    Arguments must be passed as an associative array with =>, not =, and inside brackets [].
  3. Final Answer:

    $query = new WP_Query(['category_name' => 'news']); -> Option C
  4. Quick Check:

    Correct WP_Query syntax = new + array [OK]
Quick Trick: Use new WP_Query([...]) with array syntax [OK]
Common Mistakes:
  • Omitting 'new' keyword
  • Using '=' instead of '=>' in array
  • Passing arguments without array brackets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes