Complete the code to query posts of a custom post type named 'book'.
<?php $args = array('post_type' => '[1]'); $query = new WP_Query($args); ?>
The 'post_type' argument specifies which type of posts to query. Using 'book' queries the custom post type named 'book'.
Complete the code to get only published posts of the custom post type 'movie'.
<?php $args = array('post_type' => 'movie', 'post_status' => '[1]'); $query = new WP_Query($args); ?>
The 'post_status' argument filters posts by their status. 'publish' means only published posts are returned.
Fix the error in the code to query 'event' posts ordered by date descending.
<?php $args = array( 'post_type' => 'event', 'orderby' => '[1]', 'order' => 'DESC' ); $query = new WP_Query($args); ?>
To order posts by their published date, use 'orderby' => 'date'.
Fill both blanks to query 'product' posts with a meta key 'price' greater than 20.
<?php $args = array( 'post_type' => 'product', 'meta_query' => array( array( 'key' => '[1]', 'value' => 20, 'compare' => '[2]' ) ) ); $query = new WP_Query($args); ?>
The 'meta_query' filters posts by custom fields. Use 'price' as the key and '>' to get prices greater than 20.
Fill all three blanks to query 'recipe' posts published after January 1, 2023, ordered by date ascending.
<?php $args = array( 'post_type' => '[1]', 'date_query' => array( array( 'after' => '[2]' ) ), 'orderby' => 'date', 'order' => '[3]' ); $query = new WP_Query($args); ?>
Set 'post_type' to 'recipe', 'after' date to '2023-01-01', and 'order' to 'ASC' for ascending date order.