1

I create 2 dropdowns one for each category & tag and filtering posts successfully.

After that i create a custom taxonomy cat and try to filter post between all three dropdowns. But dropdown for taxonomy cat not working.

<form action="<?php bloginfo('url'); ?>" method="get">                  
<?php
// I use custom 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;
// I use default  "Categories"
    if( $terms = get_terms( 'category', 'orderby=name' ) ) : 
        echo '<select name="category_name"> <option value="">Categories</option>';
        foreach ( $terms as $term ) :
            echo '<option value="' . $term->name . '">' . $term->name . '</option>';
        endforeach;
        echo '</select>';
    endif;
// I use default  "Tag"
    if( $terms = get_terms( 'post_tag', 'orderby=name' ) ) :
        echo '<select name="tag"><option value="">Tags</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>

Its not work for taxonomy cat & but working for others two category & tag

What I missing or any suggestions to make all three dropdown working?

Optional: This is how i create Custom Taxonomy cat

function custom_taxonomies() {
    $labels = array(
        'name' => 'Cat',
        'singular_name' => 'Cat',
        'menu_name' => 'Cat'
    );
    $args = array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'cat' )
    );
    register_taxonomy('cat', array('post'), $args); 
}
add_action( 'init' , 'custom_taxonomies' );
0

I am answering my own question. So that others can also use these type of filter.

Replacing query_var => true to query_var => cat_name

or

any other names and use it inside Form for custom taxonomy.

Then custom taxonomy react like default wordpress category and tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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