WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

- Electric
- Petrol
- Other
- 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


share|improve this question
up vote 5 down vote accepted
$args = array(
  'taxonomy'     => 'product-type',
  'hierarchical' => true,
  'title_li'     => '',
  'hide_empty'   => false

<?php wp_list_categories( $args ); ?>

You can use the wp_list_categories function also for taxonomies. http://codex.wordpress.org/Template_Tags/wp_list_categories

share|improve this answer
nice, so simple, yet so many lost hairs :) tyvm – Andy Jan 16 '12 at 20:18

Here is something I whipped up:

//Walker function
function custom_taxonomy_walker($taxonomy, $parent = 0)
    $terms = get_terms($taxonomy, array('parent' => $parent, 'hide_empty' => false));
    //If there are terms, start displaying
    if(count($terms) > 0)
        //Displaying as a list
        $out = "<ul>";
        //Cycle though the terms
        foreach ($terms as $term)
            //Secret sauce.  Function calls itself to display child elements, if any
            $out .="<li>" . $term->name . custom_taxonomy_walker($taxonomy, $term->term_id) . "</li>"; 
        $out .= "</ul>";    
        return $out;

echo custom_taxonomy_walker('category');
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.