Chained dropdown with custom taxonomies


this question is not related to any plugin or theme and i hope you dont mind me asking it. i was googling a lot but couldn’t find a solution so hopefully someone here will be able to help me.

i need to have a dropdown of custom taxonomies that change based on another dropdown menu.

what i am having now is a shortcode that will take two attributes “post type” and “categories”.

one array will hold the post types and the other will hold their related custom taxonomies in the same order in of the first array. for example – for post types, array(‘directory_post_type’, events_post_type) and for categories, array(‘directory_categories’,’events_categories’:wink:. i guess i could also do one array for each post type and its category array(‘directory_post_type’,’directory_category’:wink:, array(‘events_post_type’,’ events_category’:wink:.

what i need is an output that displays the categories in a dropdown based on what was chosen in the post type menu.

i use this code to display the custom taxonomies :

function custom_taxonomy_dropdown($taxonomy) {
$terms = get_terms($taxonomy, array('hide_empty' => 1));
echo '<select name="wprw_custom_tax_name" id="wprw_custom_tax_name">';
echo '<option value=""'; if( $_POST["wprw_custom_tax_name"] == "" ) :; echo 'selected="selected"'; endif; echo '>all</option>';
foreach ($terms as $term) {
echo '<option value="'.$term->slug .'"'; if( $_POST["wprw_custom_tax_name"] == $term->slug ) :; echo 'selected="selected"'; endif; echo '>'. $term->name . '</option>';
echo '</select>';

so basically i need to dynamically change the value of $taxonomy based on the value that comes from the first dropdown menu.

thanks in advance