Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a question I hope you can help me with. I have a custom taxonomy called locations and on the first level I have the areas (Asia, Europe, etc) and under each area I have countries (England, South Africa). What I would like to do it display a dropdown menu of all the children of that particular parent similar to what was done here, http://wordpress.org/support/topic/terms-of-custom-taxonomy-in-a-dropdown-menu . However, I want the dropdown to only display the children of the parent page I am currently on, not all the terms. So if I am on North America I want it to show the United States and Mexico and if I am on the Europe parent page I want it to show England.

Does that make sense?

Nick

share|improve this question
    
Sweetness that works great one last question. When I am on the parent page it works great but when I am on the child page it displays an empty list is there any way when on a child page it can display all the children of its parent. –  Nick Hamze Apr 14 '11 at 13:56
add comment

1 Answer

up vote 1 down vote accepted

You can use get_query_var( 'term' ) to get the current term and get_query_var( 'taxonomy' ) to get the current taxonomy, then all that is left is to use [wp_dropdown_categories()][1] function withchild_ofparameter andtaxonomy` parameter, so something like this:

//first get the current term
 $current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
//then set the args for wp_dropdown_categories
 $args = array(
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    ); 
 wp_dropdown_categories( $args );

Done!

share|improve this answer
add comment

Your Answer

 
discard

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.