0
0
Wordpressframework~10 mins

Tax queries and meta 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 with a specific taxonomy term.

Wordpress
<?php
$args = [
  'post_type' => 'post',
  'tax_query' => [
    [
      'taxonomy' => 'category',
      'field' => 'slug',
      'terms' => '[1]'
    ]
  ]
];
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Anews
Bauthor
Cdate
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using a taxonomy name instead of a term slug.
Using a post field like 'author' instead of a term slug.
2fill in blank
medium

Complete the code to query posts where meta key 'price' is greater than 100.

Wordpress
<?php
$args = [
  'post_type' => 'product',
  'meta_query' => [
    [
      'key' => 'price',
      'value' => 100,
      'compare' => '[1]',
      'type' => 'NUMERIC'
    ]
  ]
];
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
A=
BLIKE
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which only matches exactly 100.
Using 'LIKE' which is for string pattern matching.
3fill in blank
hard

Fix the error in the tax_query to filter posts with taxonomy 'genre' and term slug 'fiction'.

Wordpress
<?php
$args = [
  'post_type' => 'book',
  'tax_query' => [
    [
      'taxonomy' => '[1]',
      'field' => 'slug',
      'terms' => 'fiction'
    ]
  ]
];
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Acategory
Bgenre
Cpost_tag
Dauthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'category' which is a default taxonomy but not the one needed.
Using 'post_tag' which is for tags, not genres.
4fill in blank
hard

Fill both blanks to query posts with meta key 'rating' between 4 and 5.

Wordpress
<?php
$args = [
  'post_type' => 'movie',
  'meta_query' => [
    [
      'key' => 'rating',
      'value' => [[1], [2]],
      'compare' => 'BETWEEN',
      'type' => 'NUMERIC'
    ]
  ]
];
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
A4
B5
C3
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the lower and upper bounds.
Using values outside the expected rating scale.
5fill in blank
hard

Fill all three blanks to query posts with taxonomy 'color' term 'blue' and meta key 'size' equal to 'large'.

Wordpress
<?php
$args = [
  'post_type' => 'product',
  'tax_query' => [
    [
      'taxonomy' => '[1]',
      'field' => '[2]',
      'terms' => '[3]'
    ]
  ],
  'meta_query' => [
    [
      'key' => 'size',
      'value' => 'large',
      'compare' => '='
    ]
  ]
];
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Acolor
Bslug
Cblue
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'slug' for the field.
Using wrong taxonomy or term names.