Challenge - 5 Problems
Taxonomy Term Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this code when retrieving terms?
Consider this WordPress code snippet that retrieves terms from a taxonomy:
$terms = get_terms(array('taxonomy' => 'category', 'hide_empty' => false));
echo count($terms);What will be the output if there are 5 categories registered, but only 3 have posts assigned?Wordpress
$terms = get_terms(array('taxonomy' => 'category', 'hide_empty' => false)); echo count($terms);
Attempts:
2 left
💡 Hint
Check the 'hide_empty' parameter and what it controls.
✗ Incorrect
The 'hide_empty' => false argument tells get_terms to return all terms, even those without posts. Since there are 5 categories registered, it returns all 5.
❓ state_output
intermediate2:00remaining
What is the value of $term_name after this code runs?
Given this code snippet:
Assuming a category with slug 'news' exists and its name is 'Latest News', what will be printed?
$term = get_term_by('slug', 'news', 'category');
$term_name = $term->name ?? 'Not found';
echo $term_name;Assuming a category with slug 'news' exists and its name is 'Latest News', what will be printed?
Wordpress
$term = get_term_by('slug', 'news', 'category'); $term_name = $term->name ?? 'Not found'; echo $term_name;
Attempts:
2 left
💡 Hint
get_term_by returns a term object or false if not found.
✗ Incorrect
get_term_by returns the term object for slug 'news'. Accessing ->name gives 'Latest News'. The null coalescing operator ensures fallback if term is false.
📝 Syntax
advanced2:00remaining
Which option correctly registers a custom taxonomy with hierarchical terms?
You want to register a custom taxonomy called 'genre' for posts, allowing parent-child relationships between terms. Which code snippet correctly does this?
Attempts:
2 left
💡 Hint
Check the 'hierarchical' argument and its expected value type.
✗ Incorrect
The 'hierarchical' argument must be boolean true to enable parent-child terms. Option D uses correct syntax and value.
🔧 Debug
advanced2:00remaining
Why does this code fail to add a term to a taxonomy?
This code tries to add a term 'Thriller' to the 'genre' taxonomy:
But it does not add the term. What is the likely cause?
wp_insert_term('Thriller', 'genres'); But it does not add the term. What is the likely cause?
Wordpress
wp_insert_term('Thriller', 'genres');
Attempts:
2 left
💡 Hint
Check the taxonomy slug spelling.
✗ Incorrect
The taxonomy slug must match exactly. Using 'genres' instead of 'genre' causes the function to fail silently.
🧠 Conceptual
expert2:00remaining
What happens when you delete a taxonomy term that is assigned to posts?
In WordPress, if you delete a term from a taxonomy that is assigned to multiple posts, what is the expected behavior?
Attempts:
2 left
💡 Hint
Think about how WordPress manages term relationships on deletion.
✗ Incorrect
Deleting a term removes its association from posts but does not delete the posts themselves. Posts remain without that term.