Bird
Raised Fist0
Wordpressframework~20 mins

Custom taxonomies in Wordpress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Custom Taxonomy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this code when registering a taxonomy?
Consider this WordPress code snippet that registers a custom taxonomy. What will be the slug used for the taxonomy in the URL?

function create_movie_genre_taxonomy() {
  register_taxonomy(
    'genre',
    'movie',
    array(
      'label' => 'Genres',
      'rewrite' => array('slug' => 'film-genre'),
      'hierarchical' => true
    )
  );
}
add_action('init', 'create_movie_genre_taxonomy');
Wordpress
function create_movie_genre_taxonomy() {
  register_taxonomy(
    'genre',
    'movie',
    array(
      'label' => 'Genres',
      'rewrite' => array('slug' => 'film-genre'),
      'hierarchical' => true
    )
  );
}
add_action('init', 'create_movie_genre_taxonomy');
AThe taxonomy URL slug will be 'Genres'.
BThe taxonomy URL slug will be 'genre'.
CThe taxonomy URL slug will be 'movie'.
DThe taxonomy URL slug will be 'film-genre'.
Attempts:
2 left
💡 Hint
Look at the 'rewrite' argument in the register_taxonomy function.
❓ state_output
intermediate
2:00remaining
What is the value of 'hierarchical' for this taxonomy?
Given this code snippet, what is the effect of the 'hierarchical' argument on the taxonomy behavior?

register_taxonomy('topic', 'post', array('hierarchical' => false));
Wordpress
register_taxonomy('topic', 'post', array('hierarchical' => false));
AThe taxonomy behaves like categories with parent-child relationships.
BThe taxonomy will not be visible in the admin dashboard.
CThe taxonomy behaves like tags without parent-child relationships.
DThe taxonomy will cause a fatal error.
Attempts:
2 left
💡 Hint
Think about how WordPress treats hierarchical true vs false taxonomies.
📝 Syntax
advanced
2:00remaining
Which option will cause a syntax error when registering a taxonomy?
Identify which code snippet will cause a syntax error in WordPress when registering a custom taxonomy.
Aregister_taxonomy('genre', 'book', array('label' => 'Genres' 'hierarchical' => true));
Bregister_taxonomy('genre', 'book', array('label' => 'Genres', 'hierarchical' => true));
Cregister_taxonomy('genre', 'book', array('label' => 'Genres', 'hierarchical' => false));
Dregister_taxonomy('genre', 'book', array('label' => 'Genres', 'hierarchical' => true, 'rewrite' => array('slug' => 'genre')));
Attempts:
2 left
💡 Hint
Look carefully at the commas separating array elements.
🔧 Debug
advanced
2:00remaining
Why does this taxonomy not appear in the admin menu?
This code registers a taxonomy but it does not show up in the WordPress admin menu. What is the reason?

register_taxonomy('genre', 'post', array('show_ui' => false));
Wordpress
register_taxonomy('genre', 'post', array('show_ui' => false));
ABecause the taxonomy name 'genre' is reserved and cannot be shown.
BBecause 'show_ui' is set to false, the taxonomy UI is hidden in admin.
CBecause 'show_ui' is missing, the taxonomy defaults to hidden.
DBecause 'show_in_menu' is false by default, it hides the taxonomy.
Attempts:
2 left
💡 Hint
Check the 'show_ui' argument in register_taxonomy.
🧠 Conceptual
expert
2:00remaining
Which statement about custom taxonomies is TRUE?
Select the correct statement about custom taxonomies in WordPress.
ACustom taxonomies can be associated with multiple post types.
BCustom taxonomies must be registered before the 'init' hook runs.
CCustom taxonomies can only be hierarchical like categories.
DCustom taxonomies automatically appear in REST API without extra settings.
Attempts:
2 left
💡 Hint
Think about flexibility of taxonomies and REST API integration.

Practice

(1/5)
1. What is the main purpose of creating a custom taxonomy in WordPress?
easy
A. To increase website loading speed
B. To change the website's theme colors
C. To add new user roles
D. To organize content in a way that fits your website's needs

Solution

  1. Step 1: Understand what taxonomy means in WordPress

    Taxonomies group content like categories or tags to organize posts.
  2. Step 2: Identify the purpose of custom taxonomies

    Custom taxonomies let you create your own groups to better fit your content.
  3. Final Answer:

    To organize content in a way that fits your website's needs -> Option D
  4. Quick Check:

    Custom taxonomy = organize content [OK]
Hint: Custom taxonomies organize content, not change design or speed [OK]
Common Mistakes:
  • Confusing taxonomies with themes or plugins
  • Thinking taxonomies affect site speed
  • Mixing taxonomies with user roles
2. Which of the following is the correct way to register a custom taxonomy called genre for posts in WordPress?
easy
A. register_taxonomy('genre', 'post', array('hierarchical' => true));
B. register_taxonomy('genre', 'posts', array('hierarchical' => true));
C. register_taxonomy('genre', array('post'), 'hierarchical' => true);
D. register_taxonomy('genre', 'post', 'hierarchical' => true);

Solution

  1. Step 1: Check the function signature of register_taxonomy()

    The function requires taxonomy name, object type(s) as string or array, and an array of arguments.
  2. Step 2: Verify correct parameter types and syntax

    register_taxonomy('genre', 'post', array('hierarchical' => true)); uses 'post' as string and an array for arguments correctly.
  3. Final Answer:

    register_taxonomy('genre', 'post', array('hierarchical' => true)); -> Option A
  4. Quick Check:

    Correct syntax uses array for args and string for post type [OK]
Hint: Use array() for args and string or array for post types [OK]
Common Mistakes:
  • Using plural 'posts' instead of 'post'
  • Passing arguments outside an array
  • Wrong parameter order
3. Given this code snippet:
register_taxonomy('genre', 'post', array('hierarchical' => true));
$terms = get_terms(array('taxonomy' => 'genre', 'hide_empty' => false));
foreach ($terms as $term) {
echo $term->name . ', ';
}

What will this code output if there are two terms 'Fiction' and 'Non-Fiction' assigned to posts?
medium
A. genre, Fiction, Non-Fiction
B. Fiction, Non-Fiction,
C. Array
D. Error: Undefined variable

Solution

  1. Step 1: Understand get_terms() usage

    get_terms() fetches terms of the taxonomy 'genre' including empty ones due to 'hide_empty' => false.
  2. Step 2: Loop through terms and print their names

    The foreach loop prints each term's name followed by a comma and space.
  3. Final Answer:

    Fiction, Non-Fiction, -> Option B
  4. Quick Check:

    Loop prints term names separated by commas [OK]
Hint: get_terms returns term objects; loop prints their names [OK]
Common Mistakes:
  • Expecting taxonomy name instead of term names
  • Confusing array output with string
  • Not setting 'hide_empty' causing missing terms
4. What is wrong with this code snippet for registering a custom taxonomy?
register_taxonomy('genre', 'post', 'hierarchical' => true);
medium
A. The post type should be an array, not a string
B. The taxonomy name must be plural
C. The third argument should be an array, not a key-value pair directly
D. The function name is incorrect

Solution

  1. Step 1: Check the function parameters

    register_taxonomy() expects the third argument as an array of arguments.
  2. Step 2: Identify the error in argument format

    The code passes 'hierarchical' => true directly, not inside an array, causing syntax error.
  3. Final Answer:

    The third argument should be an array, not a key-value pair directly -> Option C
  4. Quick Check:

    Args must be in array() [OK]
Hint: Always wrap arguments in array() for register_taxonomy [OK]
Common Mistakes:
  • Passing arguments without array()
  • Using plural taxonomy names incorrectly
  • Wrong function name like register_taxonomies
5. You want to create a custom taxonomy called location that behaves like tags (non-hierarchical) and attach it to both post and event post types. Which code snippet correctly achieves this?
hard
A. register_taxonomy('location', array('post', 'event'), array('hierarchical' => false));
B. register_taxonomy('location', 'post', array('hierarchical' => false)); register_taxonomy('location', 'event', array('hierarchical' => false));
C. register_taxonomy('location', array('post', 'event'), array('hierarchical' => true));
D. register_taxonomy('location', array('post', 'event'), array('hierarchical' => true, 'tags' => true));

Solution

  1. Step 1: Understand hierarchical argument for tags

    Tags are non-hierarchical, so 'hierarchical' must be false.
  2. Step 2: Attach taxonomy to multiple post types

    Pass an array of post types ['post', 'event'] as second argument.
  3. Step 3: Check options for correct syntax and behavior

    register_taxonomy('location', array('post', 'event'), array('hierarchical' => false)); correctly sets 'hierarchical' => false and attaches to both post types in one call.
  4. Final Answer:

    register_taxonomy('location', array('post', 'event'), array('hierarchical' => false)); -> Option A
  5. Quick Check:

    Non-hierarchical + multiple post types = register_taxonomy('location', array('post', 'event'), array('hierarchical' => false)); [OK]
Hint: Use array for post types and set hierarchical false for tags [OK]
Common Mistakes:
  • Setting hierarchical true for tags
  • Calling register_taxonomy twice unnecessarily
  • Passing post types as string instead of array
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard