I have been trying google for this, but not so easy to search for. I have a custom hierarchical taxonomy, something along the lines of:
Chainsaws
- Electric
- Petrol
- Other
Grasscutters
- Electric
- Petrol
- Other
What I need to do is create an index page, retaining the hierarchical structure.
The closest I have come to doing it is with:
$products = get_terms('product-type');
foreach ($products as $product) {
$out .= $product->name;
}
But this just shows the ones in use, and loses it hierarchy 🙁
Any insights are very welcome.
Thanks in advance
Andy
2 Answers
<?php
$args = array(
'taxonomy' => 'product-type',
'hierarchical' => true,
'title_li' => '',
'hide_empty' => false
);
?>
<ul>
<?php wp_list_categories( $args ); ?>
</ul>
You can use the wp_list_categories function also for taxonomies. http://codex.wordpress.org/Template_Tags/wp_list_categories