What will be Taxonomy name to get value with dropdown

by FRQ6692   Last Updated May 22, 2018 11:08 AM

Trying to create Dropdown filter for two custom taxonomy cat & genre.

What and how to set name in <select name="?"> for each Hierarchical and Nonhierarchical taxonomy?

As for default wordpress taxonomy's we use category_name for hierarchical & tag for Nonhierarchical.

<form action="<?php bloginfo('url'); ?>" method="get">                  
<?php
// Hierarchical taxonomy  "cat"
    if( $terms = get_terms( 'cat', 'orderby=name' ) ) :
        echo '<select name="cat_name"> <option value="">Cat</option>';
        foreach ( $terms as $term ) :
            echo '<option value="' . $term->name . '">' . $term->name . '</option>';
        endforeach;
        echo '</select>';
    endif;
// Nonhierarchical taxonomy  "genre"
        <?php if( $terms = get_terms( 'genre', 'orderby=name' ) ) :
        echo '<select name="genre"><option value="">genre</option>';
        foreach ( $terms as $term ) :
            echo '<option value="' . $term->name . '">' . $term->name . '</option>';
        endforeach;
        echo '</select>';
    endif;
?>
<input type="submit" name="submit" value="filter" />
</form>

This code not working when i set name with same rule for hierarchical & Nonhierarchical.



Related Questions


Can I limit term selection to one plus parent?

Updated April 22, 2016 08:03 AM

Create multidimensional array of taxonomies

Updated October 17, 2017 19:08 PM

Why does wp_remove_object_terms not work?

Updated April 01, 2018 06:08 AM