Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get all terms of a taxonomy.
Wordpress
<?php $terms = get_terms(array('taxonomy' => '[1]')); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' or 'page' instead of taxonomy name.
✗ Incorrect
The get_terms function requires the taxonomy name, such as 'category', to fetch terms.
2fill in blank
mediumComplete the code to create a new term in a taxonomy.
Wordpress
<?php wp_insert_term('New Term', '[1]'); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-taxonomy names like 'author' or 'comment'.
✗ Incorrect
The second argument of wp_insert_term is the taxonomy slug, like 'category'.
3fill in blank
hardFix the error in the code to get terms with no empty results.
Wordpress
<?php $terms = get_terms(array('taxonomy' => 'category', 'hide_empty' => [1])); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' hides empty terms.
Using 0 may not work as expected.
✗ Incorrect
Setting hide_empty to false ensures terms with no posts are included.
4fill in blank
hardFill both blanks to update a term's name and slug.
Wordpress
<?php wp_update_term([1], 'category', array('name' => 'Updated Name', 'slug' => '[2]')); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using slug as a number.
Using term ID as a string slug.
✗ Incorrect
The first argument is the term ID (e.g., 15), and the slug is a string like 'updated-name'.
5fill in blank
hardFill all three blanks to register a custom taxonomy.
Wordpress
<?php register_taxonomy('[1]', '[2]', array('label' => '[3]')); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'category' as taxonomy slug for custom taxonomy.
Mixing label and slug.
✗ Incorrect
First is the taxonomy slug ('genre'), second is the post type ('post'), third is the label ('Genres').