Wordpress - WordPress Query and DatabaseWhich 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']);Check Answer
Step-by-Step SolutionSolution:Step 1: Check WP_Query instantiation syntaxWP_Query must be instantiated with 'new' and an array of arguments.Step 2: Validate array syntaxArguments must be passed as an associative array with =>, not =, and inside brackets [].Final Answer:$query = new WP_Query(['category_name' => 'news']); -> Option CQuick Check:Correct WP_Query syntax = new + array [OK]Quick Trick: Use new WP_Query([...]) with array syntax [OK]Common Mistakes:Omitting 'new' keywordUsing '=' instead of '=>' in arrayPassing arguments without array brackets
Master "WordPress Query and Database" in Wordpress9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Wordpress Quizzes Custom Fields and Meta Data - Displaying custom field data - Quiz 11easy Custom Post Types and Taxonomies - Custom post type arguments - Quiz 1easy Custom Post Types and Taxonomies - Archive pages for custom types - Quiz 14medium Custom Theme Development - Responsive theme patterns - Quiz 10hard Custom Theme Development - Responsive theme patterns - Quiz 3easy Shortcodes and Blocks - Block attributes and controls - Quiz 8hard Shortcodes and Blocks - Block registration - Quiz 7medium Shortcodes and Blocks - Shortcodes with parameters - Quiz 15hard WordPress Hooks System - Why hooks enable extensibility - Quiz 3easy WordPress Query and Database - WP_Query class - Quiz 14medium