Codeable info

List Terms of a Custom Taxonomy

Posted on by in WordPress Tutorials

Once you have registered your custom taxonomy, it is really useful for be able to list the terms inside of that taxonomy, exactly as you would display a list of post categories.

Even though it is a little misleading, it turns out that you can display a list of terms in a custom taxonomy using the wp_list_categories() function.

The function accepts a variety of parameters, which you can see by going to codex entry, but I will just show you a couple of the most useful and commonly used ones.

1
2
3
4
5
6
7
8
9
echo '<ul>';
$args_list = array(
	'taxonomy' => 'genre', // Registered tax name
	'show_count' => true,
	'hierarchical' => true,
	'echo' => '0',
);	 
echo wp_list_categories($args_list);
echo '</ul>';

This will display all of the terms inside of the “genre” taxonomy as an unordered list. It will also display a post count next to each taxonomy name, each taxonomy will be linked, and it will indent child terms.

Where to Go from Here?

This snippet is great for developers, but it could be take a little further and be placed into a widget that provides users a way to select the taxonomy terms they would like to display from the widget options. If you want to take on this task, check out my “blank widget template“. It will give you just about everything you need to know.

)
Codeable info

Comments (3)

Comment by Aniket says:

is there a way where in i can display selected taxonomies under ‘genre’?

Comment by woch says:

Excelente tip!!!

Muchisimas gracias, me has ayudado bastante.

Comment by Eliza says:

Thank you! :D

You helped me a lot!

Codeable info