First create a function to display your search form
function display_custom_search_form($atts){
$return = '<form role="search" method="get" id="searchform" action="'.home_url( '/' ).'">
<div><label class="screen-reader-text" for="s">Search for:</label>
'.wp_dropdown_categories(array('name' =>'taxTerm', 'taxonomy' => 'TAXONOMY_NAME').'
<!-- this is the magic field you will need to change in order for this to work with each post types--->
<input type="hidden" name="post_type" value="post" />
<input type="submit" id="searchsubmit" value="Search" />
<input type="hidden" name="custom_search" value="1">
</div>
</form>';
if ($echo){
echo $return;
}else{
return $return;
}
}
hook this function as a shortcode so you could use it anywhere you want (post/page/widget)
add_shortcode('my_c_s','display_custom_search_form');
add_filter('widget_text', 'do_shortcode');
then you check if the form is submitted and if so you can filter the posts based on that:
//was the form submitted
if (isset($_GET['custom_search']) && $_GET['custom_search'] == 1){
add_filter('pre_get_posts','Custom_Search_Filter');
}
//function to actually filter the posts based on the taxonomy term and post type
function Custom_Search_Filter($query) {
//only do this on search
if (is_search()){
//first check for the first type if not set then its the default post.
$post_type = $_GET['post_type'];
if (!$post_type) {
$post_type = 'post';
}
$query->set('post_type', $post_type);
//then check for the taxonomy term
if (isset($_GET['taxTerm'])){
$query->set('TAXONOMY_NAME', $_GET['taxTerm']);
}
}
return $query;
}
copy all of the code in to you theme's functions.php
and change TAXONOMY_NAME to your actual custom taxonomy name (its there twice).
open your widgets panel and add a simple text widget with [my_c_s]
inside and save.