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 know this question is asked many times on stack-exchange, but I am with something new

I want to have three Drop Down Boxes and a search button, the drop-down boxes will contain terms of 3 custom taxonomies, when I will select three values in it and hit search, I will get results which will be having these three terms in that post

It sounds weird but this is really a helpful search for a website

I am having a code(which I found on some website) which is working, but just for categories and only gives one drop down box, I want to make it for custom taxonomy which will be having 3 drop-down boxes, here is my code:

function wp_search_form($form) {
$form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
<div><label class="hidden" for="s">' . __('Search for:') . '</label>
<input type="text" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'.attribute_escape(__('Search')).'" />
<br />
'.wp_dropdown_categories('show_option_all=All Categories&hide_empty=0&echo=0&selected='.intval($_GET['cat']).'').'
</div>
</form>';
return $form;
}

After writing this I have to just echo it, <?php echo wp_search_form(''); ?>

I edited according to my view, I just changed a single line to display the drop-down of custom taxonomy but when hitting on search it gives me No results found, Code I changed is this '.wp_dropdown_categories('taxonomy=location&hide_empty=0&echo=0&selected='.intval($_GET['cat']).'').'

Location is my custom taxonomy name

share|improve this question
1  
Are you talking about three different taxonomies? In that case, WordPress before 3.1 didn't support querying over multiple taxonomies. However, scribu (who wrote this new feature) also created a plugin to add this to older versions of WordPress. –  Jan Fabry Feb 21 '11 at 14:19
    
@jan - sorry just now i saw your comment. –  Bainternet Feb 21 '11 at 16:15
    
@בניית אתרים : Unrelated to this question, but do you get a notification for this comment? Because your name contains no ASCII characters, there is some concern this would not work. –  Jan Fabry Feb 22 '11 at 8:22
add comment

2 Answers 2

up vote 1 down vote accepted

Wordpress in version prior to 3.1 does not support querying multiple taxonomies, you will need to install Scribu's plugin Query Multiple Taxonomies to fix that. and in order to get the dropdown select box you can use wp_dropdown_categories() like this:

$args = array(
    'taxonomy' => 'location',
    'hide_empty' => 0,
    'echo' => 1,
    'name' => 'location'
);
if (isset($_GET['location'])){
    $args['selected'] = intval($_GET['location']);
}
wp_dropdown_categories( $args );
share|improve this answer
    
After installing the plugin, then directly should I add drop-down boxes of taxonomies? and click on submit? I think it will give 404 or No Results found –  ntechi Feb 21 '11 at 16:16
1  
Try it and report back –  Bainternet Feb 21 '11 at 18:00
    
@בניית אתרים @Jan Fabry OK I tried, this worked for me, but now new problem created, for the posts where their are no taxonomies selected, they are giving me 404 page and that too when just clicking on that post not on searching –  ntechi Feb 22 '11 at 9:51
add comment

I have just finished development of a plugin that allows you add as many dropdown boxes for your categories, tags or custom taxonomies, it also includes an optional search field in case you do not just want to do filtering:

Wordpress Seach & Filter for Taxonomies

You can use it as a shortcode like this in a post or widget:

[searchandfilter taxonomies="category,post_tag"]

or use it in your theme file:

<?php echo do_shortcode( '[searchandfilter taxonomies="category,post_tag"]' ); ?>

Hope it helps :)

share|improve this answer
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.