WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/">

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
if ($term->parent == 0) {  
&title_li=&child_of=' . $term->term_id);
} else {
&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>



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?

share|improve this question
up vote 0 down vote accepted

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?

share|improve this answer
Thanks for your response, it is helpful. However I also am trying to figure out what would be the best way to go about this. When using a plugin (which I don't want to use) the correct returned url for a selected category and "all" states looks like this - domain.com/blog/videoscategory/animal-law-essentials/?states When selecting a category and state, the correct URL should look something like this - domain.com/… but as of now, the form is returning the URL like this - domain.com/blog/videoscategory/?cat=190&cat=87 – mygm26 Dec 16 '12 at 1:10
Ok I changed the form action to action="<?php echo $PHP_SELF; ?>" and now when I submit the form to filter the URL returns as - domain.com/blog/videoscategory/wills-trusts-and-estates/… How can I use this to filter/sort? – mygm26 Dec 16 '12 at 7:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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