Complete the code to create a custom query that retrieves posts of type 'product'.
<?php $args = array('post_type' => '[1]'); $query = new WP_Query($args); ?>
The 'post_type' argument specifies which type of posts to retrieve. Using 'product' fetches only product posts.
Complete the code to retrieve posts ordered by their publish date in descending order.
<?php $args = array('orderby' => '[1]', 'order' => 'DESC'); $query = new WP_Query($args); ?>
Ordering by 'date' sorts posts by their publish date. 'DESC' means newest first.
Fix the error in the code to retrieve posts with the category ID 5.
<?php $args = array('cat' => [1]); $query = new WP_Query($args); ?>
The 'cat' parameter expects an integer ID, so 5 without quotes is correct.
Fill both blanks to retrieve posts with meta key 'price' greater than 100.
<?php $args = array( 'meta_key' => '[1]', 'meta_value' => 100, 'meta_compare' => '[2]' ); $query = new WP_Query($args); ?>
'meta_key' specifies the custom field name, and 'meta_compare' with '>' filters values greater than 100.
Fill all three blanks to retrieve published 'event' posts ordered by title ascending.
<?php $args = array( 'post_type' => '[1]', 'post_status' => '[2]', 'orderby' => '[3]', 'order' => 'ASC' ); $query = new WP_Query($args); ?>
'post_type' set to 'event' fetches event posts, 'post_status' 'publish' gets only published posts, and ordering by 'title' sorts alphabetically.