0
0
Wordpressframework~10 mins

Custom post type queries in Wordpress - Interactive Code Practice

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

Complete the code to query posts of a custom post type named 'book'.

Wordpress
<?php
$args = array('post_type' => '[1]');
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Apage
Bpost
Cbook
Dproduct
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of the custom post type name.
Using 'page' which queries pages, not custom posts.
2fill in blank
medium

Complete the code to get only published posts of the custom post type 'movie'.

Wordpress
<?php
$args = array('post_type' => 'movie', 'post_status' => '[1]');
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Apublish
Bpending
Cprivate
Ddraft
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'draft' which returns unpublished posts.
Using 'private' which returns posts visible only to admins.
3fill in blank
hard

Fix the error in the code to query 'event' posts ordered by date descending.

Wordpress
<?php
$args = array(
  'post_type' => 'event',
  'orderby' => '[1]',
  'order' => 'DESC'
);
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Adate
Btitle
Cmenu_order
Dauthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'title' which orders alphabetically by title.
Using 'author' which orders by author name.
4fill in blank
hard

Fill both blanks to query 'product' posts with a meta key 'price' greater than 20.

Wordpress
<?php
$args = array(
  'post_type' => 'product',
  'meta_query' => array(
    array(
      'key' => '[1]',
      'value' => 20,
      '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 'cost' instead of 'price' as meta key.
Using '<' which filters for prices less than 20.
5fill in blank
hard

Fill all three blanks to query 'recipe' posts published after January 1, 2023, ordered by date ascending.

Wordpress
<?php
$args = array(
  'post_type' => '[1]',
  'date_query' => array(
    array(
      'after' => '[2]'
    )
  ),
  'orderby' => 'date',
  'order' => '[3]'
);
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Arecipe
B2023-01-01
CASC
DDESC
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'DESC' order which sorts newest first instead of oldest.
Using wrong date format or post type.