0
0
Wordpressframework~10 mins

Why custom queries retrieve specific data in Wordpress - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a custom query that retrieves posts of type 'product'.

Wordpress
<?php
$args = array('post_type' => '[1]');
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Apage
Bpost
Cproduct
Dattachment
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'product' will fetch blog posts, not products.
Leaving 'post_type' empty fetches default posts.
2fill in blank
medium

Complete the code to retrieve posts ordered by their publish date in descending order.

Wordpress
<?php
$args = array('orderby' => '[1]', 'order' => 'DESC');
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Atitle
Bdate
Cauthor
Dmodified
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'title' orders alphabetically, not by date.
Using 'author' orders by who wrote the post.
3fill in blank
hard

Fix the error in the code to retrieve posts with the category ID 5.

Wordpress
<?php
$args = array('cat' => [1]);
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Acategory
B'5'
C"5"
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes makes the ID a string, which causes the query to fail.
Using 'category' instead of the ID is incorrect.
4fill in blank
hard

Fill both blanks to retrieve posts with meta key 'price' greater than 100.

Wordpress
<?php
$args = array(
  'meta_key' => '[1]',
  'meta_value' => 100,
  'meta_compare' => '[2]'
);
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Aprice
B>
C<
Dcost
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will get values less than 100, which is wrong here.
Using wrong meta key names will return no results.
5fill in blank
hard

Fill all three blanks to retrieve published 'event' posts ordered by title ascending.

Wordpress
<?php
$args = array(
  'post_type' => '[1]',
  'post_status' => '[2]',
  'orderby' => '[3]',
  'order' => 'ASC'
);
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Aevent
Bpublish
Ctitle
Ddraft
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'draft' status will not show published posts.
Ordering by anything other than 'title' changes the sort order.