0

I am trying to create a form on the taxonomy template that will be able to filter the posts the current user is viewing. I want to use a few drop downs and submit button to do so.

My code looks like this -

`

<form method="get" id="searchform" name="searchform" action="<?php echo home_url(); ?>/blog/videoscategory/">


<?php 
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
if ($term->parent == 0) {  
wp_dropdown_categories('taxonomy=videoscategory&hide_if_empty=true&depth=2&show_count=0
&title_li=&child_of=' . $term->term_id);
} else {
wp_dropdown_categories('taxonomy=videoscategory&hide_if_empty=true&show_count=0
&title_li=&child_of=' . $term->parent); 
}
?>


<?php wp_dropdown_categories('show_option_all=All U.S. States&taxonomy=states&depth=2&orderby=name&show_count=1'); ?>
<button tabindex="2" type="submit" class="search_btn"> 

<span style="background-image:url('/2012/08/smallglass.png'); background-repeat:no-repeat; display:inline-block; margin:0px auto; height:20px; width:20px; text-align:center;"></span>

</button>
</form>

`

The category pages URL looks like this - http://domain.com/blog/videoscategory/bankruptcy-law/

When I submit the form (using 2 dropdowns - sub category and custom tags taxonomy) the url returns like this - http://domain.com/blog/videoscategory/?cat=273&cat=87

How can I correct this? Or is there a better way about going about using a form to sort posts?

1 Answer 1

0

That happens because wp_dropdown_categories, by default, defines the name of the dropdowns as 'cat'.

You are showing 2 dropdowns in the form, and both are named 'cat', because you didn't define a name for them. So when you submit the form, you get two query vars named cat.

For example, if you want the second dropdown to be called states, you would have something like this:

<?php wp_dropdown_categories('name=states&show_option_all=All U.S. States&taxonomy=states&depth=2&orderby=name&show_count=1'); ?>

But how do you plan to use these dropdowns in filtering the content?

2

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