Complete the code to create a new WP_Query object.
$query = new [1](['post_type' => 'post']);
The WP_Query class is used to create custom queries in WordPress. You create a new instance by calling new WP_Query().
Complete the code to check if the query has posts.
if ($query->[1]()) { echo 'Posts found'; }
The method have_posts() checks if the query returned any posts.
Fix the error in the loop to display post titles.
while ($query->[1]()) { $query->the_post(); the_title(); }
the_post() in the while condition (it does not return a boolean).get_post() or next_post().The method have_posts() is used in the while condition to iterate over the posts. the_post() sets up the post data inside the loop.
Fill both blanks to create a query for 5 recent posts of type 'product'.
$args = ['post_type' => [1], 'posts_per_page' => [2]]; $query = new WP_Query($args);
To query 5 recent 'product' posts, set post_type to 'product' and posts_per_page to 5.
Fill all three blanks to loop through posts and display their titles with links.
if ($query->[1]()) { while ($query->[2]()) { $query->the_post(); echo '<a href="' . get_permalink() . '">' . [3]() . '</a><br>'; } }
Use have_posts() to check for posts and as the loop condition, the_post() sets up each post inside the loop, and the_title() to display the title.