The requirement is where i have a taxonomy State which is the parent and it has a child sub-taxonomies they are the Cities, Need to display the state as a drop down, when i select the particular state tax i have to display the corresponding child cities of the state tax in the second drop down.....kindly help me..

I found the solution for the above problem, but it works partial........anyone with solution kindly help me....

Add the below code at the top of the template page after get_header(), as you can see i added a custom taxonomy 'state' in the wp_dropdown_categories....

<?php get_header(); ?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript">
    var $mainCat=$('#main_cat').val();

    // call ajax
            url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",     
            data:'action=my_special_ajax_call&main_catid=' + $mainCat,

                //  alert(results);
<style type="text/css">
#content{width:auto; height:400px; margin:50px;}
<div id="content">
 wp_dropdown_categories('show_count=0&selected=-1&hierarchical=1&depth=1&hide_empty=0&exclude=1&show_option_none=Main Categories&name=main_cat&taxonomy=state');
<select name="sub_cat" id="sub_cat" disabled="disabled"></select>

Add the below code in functions.php file........

function implement_ajax() {
    $categories=  get_categories('child_of='.$_POST['main_catid'].'hide_empty=0'); 
      foreach ($categories as $cat) {
        $option .= '<option value="'.$cat->term_id.'">';
        $option .= $cat->cat_name;
        $option .= ' ('.$cat->category_count.')';
        $option .= '</option>';
      echo '<option value="-1" selected="selected">Sub Categories</option>'.$option;
    } // end if
add_action('wp_ajax_my_special_ajax_call', 'implement_ajax');
add_action('wp_ajax_nopriv_my_special_ajax_call', 'implement_ajax');//for users that are not logged in.

So now this is my structure....


  • CT1-1
  • CT2-1
  • CT3-1


  • CT1-2
  • CT2-2
  • CT3-2


  • CT1-3
  • CT2-3
  • CT3-3

im able to display the parent taxonomies when i select the parent taxonomy the second drop gets activated but it does not populate the child items except it shows the static output " Select "..... I'm not a Pro so kindly bare with me, Can anyone kindly resolve this issue

1 Answer 1


Hello Everyone out there, who are facing difficulty to display the parent and child taxonomies in drop down, i found the solution for the above problem......

edit the code in the functions.php file,

before the code was

$categories=  get_categories('child_of='.$_POST['main_catid'].'hide_empty=0');

now edit the code, like this...

$categories=  get_categories('child_of='.$_POST['main_catid'].'&hide_empty=0'.'&taxonomy=state');

and this works so beautifully, try it for sure......all i did was i concatenated the taxonomy, that's all

cheers everyone, happy coding..... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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