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'm building a <select> dropdown to display a list of terms for a custom hierarchical taxonomy. How do I know the depth of each term? I'd like to add some indentation for child-terms (the more deeply they're nested, the more indentation there should be).

However I'm not able to retrieve the depth level from get_terms(). How to get the depth level as an integer?

share|improve this question
up vote 1 down vote accepted

You can use wp_dropdown_categories():

Display or retrieve the HTML dropdown list of categories.

$args = array(
    'show_count'   => 1,
    'hierarchical' => 1,
    'taxonomy'     => 'my_taxonomy',

wp_dropdown_categories( $args );
share|improve this answer
Thanks, but I have a problem with this solution... what if I want to insert some onchange javascript in the <select> and put the term link in the <option> value? In this way the user would get redirected to the term archive by selecting the corresponding item in the list. wp_dropdown_categories() only outputs a plain list if I'm not mistaken. – unfulvio Jan 15 '13 at 13:38
uh... just thought of it, maybe I can create a custom walker for wp_dropdown_categories... – unfulvio Jan 15 '13 at 13:41
or even more practically, I could do this with javascript, just found a valid example in codex codex.wordpress.org/Function_Reference/wp_dropdown_categories - apparently wp_dropdown_categories doesn't accept a custom walker in the args – unfulvio Jan 15 '13 at 13:55
But basically, your question has been answered? It would be nice if you could do the job with javascript. – Mike Madern Jan 15 '13 at 13:59
there is some method descriped in codex.wordpress.org/Function_Reference/wp_dropdown_categories but URLs created with those methods will return 404 if one uses pretty permalinks, URL rewrites seem not to correct the problem (or maybe they work with blog posts only? in my case is a custom taxonomy) – unfulvio Jan 15 '13 at 17:06

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.