How to show a hierarchical terms list?

I have a hierarchical taxonomy called ‘geographical locations’. It contains continents on a first level, and then the countries for each one. Example :

- Ireland
- Spain
- Sweden
- Laos
- Thailand
- Vietnam


Using get_terms() I managed to output the full list of terms, but the continents get mixed up with the countries, in one big flat list.

How can I output a hierarchical list like above?


Use wp_list_categories with the 'taxonomy' => 'taxonomy' argument, it’s built for creating hierarchical category lists but will also support using a custom taxonomy..

Codex Example:
Display terms in a custom taxonomy

If the list comes back looking flat, it’s possible you just need a little CSS to add padding to the lists, so you can see their hierarchical structure.

Leave a Comment