0
0
Wordpressframework~20 mins

Taxonomy term management in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Taxonomy Term 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 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);
A3
B0
C5
DError: get_terms not found
Attempts:
2 left
💡 Hint
Check the 'hide_empty' parameter and what it controls.
state_output
intermediate
2:00remaining
What is the value of $term_name after this code runs?
Given this code snippet:
 $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;
ALatest News
BError: Trying to get property of non-object
CNot found
Dnews
Attempts:
2 left
💡 Hint
get_term_by returns a term object or false if not found.
📝 Syntax
advanced
2: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?
Aregister_taxonomy('genre', 'post', array('parent_child' => true));
Bregister_taxonomy('genre', 'post', array('hierarchical' => false));
Cregister_taxonomy('genre', array('post'), array('hierarchical' => 'yes'));
Dregister_taxonomy('genre', 'post', array('hierarchical' => true));
Attempts:
2 left
💡 Hint
Check the 'hierarchical' argument and its expected value type.
🔧 Debug
advanced
2: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:
 wp_insert_term('Thriller', 'genres'); 

But it does not add the term. What is the likely cause?
Wordpress
wp_insert_term('Thriller', 'genres');
Awp_insert_term requires a third argument for term description.
BThe taxonomy name is incorrect; it should be 'genre' not 'genres'.
CThe term 'Thriller' already exists, so it won't add again.
Dwp_insert_term only works for built-in taxonomies.
Attempts:
2 left
💡 Hint
Check the taxonomy slug spelling.
🧠 Conceptual
expert
2: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?
AThe term is removed from all posts, but the posts remain intact.
BThe posts assigned to the term are deleted automatically.
CThe term cannot be deleted if assigned to posts; an error occurs.
DThe posts keep the term ID, but it becomes orphaned and inaccessible.
Attempts:
2 left
💡 Hint
Think about how WordPress manages term relationships on deletion.