0
0
Wordpressframework~10 mins

Custom taxonomies 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 register a custom taxonomy called 'genre'.

Wordpress
<?php
register_taxonomy('[1]', 'book', array(
  'label' => 'Genres',
  'hierarchical' => true
));
?>
Drag options to blanks, or click blank then click option'
Atag
Bcategory
Cgenre
Dauthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using built-in taxonomy names like 'category' or 'tag' instead of a custom name.
Forgetting to put the taxonomy name as the first argument.
2fill in blank
medium

Complete the code to attach the 'genre' taxonomy to the 'book' post type.

Wordpress
<?php
register_taxonomy('genre', '[1]', array(
  'label' => 'Genres',
  'hierarchical' => true
));
?>
Drag options to blanks, or click blank then click option'
Abook
Bpage
Cpost
Dmovie
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different post type like 'post' or 'page' instead of 'book'.
Passing an array instead of a string when only one post type is used.
3fill in blank
hard

Fix the error in the code to make the taxonomy hierarchical.

Wordpress
<?php
register_taxonomy('genre', 'book', array(
  'label' => 'Genres',
  'hierarchical' => [1]
));
?>
Drag options to blanks, or click blank then click option'
A'true'
Btrue
C1
D'false'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' as a string instead of boolean true.
Using 1 instead of true (works but less clear).
4fill in blank
hard

Fill both blanks to register a non-hierarchical taxonomy called 'topic' for posts.

Wordpress
<?php
register_taxonomy('[1]', '[2]', array(
  'label' => 'Topics',
  'hierarchical' => false
));
?>
Drag options to blanks, or click blank then click option'
Atopic
Bpost
Cpage
Dcategory
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'category' as taxonomy name which is built-in.
Attaching taxonomy to 'page' instead of 'post'.
5fill in blank
hard

Fill all three blanks to register a custom taxonomy 'skill_level' for a custom post type 'course' with labels and hierarchical true.

Wordpress
<?php
register_taxonomy('[1]', '[2]', array(
  'label' => '[3]',
  'hierarchical' => true
));
?>
Drag options to blanks, or click blank then click option'
Askill_level
Bcourse
CSkill Levels
Dlevel
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase label without spaces.
Mixing up taxonomy name and label.