Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.