0

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

3

2 Answers 2

1

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 );
3
  • 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 Feb 21, 2011 at 16:16
  • 1
    Try it and report back
    – Bainternet
    Feb 21, 2011 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 Feb 22, 2011 at 9:51
0

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 :)

1
  • added, showing as needed but not working
    – Billu
    Oct 10, 2018 at 10:55

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.