Is it possible to limit a search for keywords to a specific post type (say 'news') but filter the results by selected custom taxonomies?
- I have a news section.
- This has the custom post type called 'news'.
- This then has the custom taxonomy 'news-category'.
- There are several custom taxonomy terms that need to be listed with checkboxes next to them.
Say for instance someone wants to search for the keyword "Wales" and they check the custom taxonomies "Medical" and "Financial", then it displays the results by those search queries.
To sum up, they are only searching within the news post type which is filtered by the custom taxonomies and keyword. Is this possible? If so, how?
UPDATE:
I have a template called archive-members.php with the following, how can I wrap all this with the necessary code to show a search with keyword+category, just keyword or just category.
<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/
get_header();
?>
<!-- Main Content -->
<div class="post" id="post-<?php the_ID(); ?>">
<div class="entry">
<div class="left-search">
<div class="page-title-search">
<h2>Search</h2>
<form id="custom-search" action="<?php bloginfo('url'); ?>/" method="get">
<?php //Get all (non-empty) terms for taxonomy 'news-category'
$args = array('orderby' => 'name','order' => 'ASC');
$categories = get_terms( 'members', $args );
?>
<!-- Visible input for search term -->
<p style="margin-bottom:5px!IMPORTANT;"><b>Keyword</b></p>
<input type="text" class="keyword" name="s" value="" />
<div class="clear"></div>
<p style="margin-top:20px!IMPORTANT;margin-bottom:2px!IMPORTANT;"><b>Specialisms</b></p>
<?php //Display checkbox for each term
$counter = 1;
foreach ($categories as $category) {
echo '<input type="checkbox" id="field-'.$counter.'" class="mycheckbox" name="mw-filter-terms[]" value="'.$category->slug.'">';
echo '<label for="field-'.$counter.'" class="mycheckbox-label">'.esc_html($category->name).'</label>';
$counter++;
} ?>
<!-- Hidden input to set post type to news-->
<input type="hidden" name="post_type" value="members" />
<div class="clear"></div>
<!-- Submit button -->
<button class="blue medium awesome awesomeforward awesomesearch" type="submit">Search</button>
</form>
</div>
</div>
<div class="news-content" style="background-color:#ececec!IMPORTANT;">
<div class="page-title-content">
<h2>Members Directory</h2>
</div>
<div class="news-content-inner">
<div class="inner-holder">
<?php the_field('content', 1886); ?>
</div>
</div>
<a class="blue medium awesome awesomeforward" style="margin-left:193px;margin-bottom:10px;color: white !important; " href="<?php bloginfo('url'); ?>/member-signup/">Become A Member</a>
<div class="news-content" style="background-color:#ececec!IMPORTANT;">
<div class="page-title-content">
<h2>Search Results</h2>
</div>
<div class="news-content-inner">
<?php $portfolioloop1 = new WP_Query( array( 'paged' => get_query_var('paged'), 'order' => 'ASC', 'orderby' => 'title', 'post_status' => 'publish', 'post_type' => 'members', 'posts_per_page' => 300 ) ); ?>
<?php while ( $portfolioloop1->have_posts() ) : $portfolioloop1->the_post(); ?>
<div <?php if (get_field('logo') != "") { ?>style="height:120px;"<?php } ?> class="news-item" onclick="location.href='<?php echo the_permalink(); ?>'">
<?php if (get_field('logo') != "") { ?>
<div style="height:110px;float:left;">
<table>
<tr>
<td height="110">
<img style="margin-right:15px;" src="<?php echo the_field('logo'); ?>" width="150" alt="<?php echo the_title(); ?>" />
</td>
</tr>
</table>
</div>
<?php } ?>
<div <?php if (get_field('logo') != "") { ?>style="float:left;width:379px;"<?php } ?>>
<h2><a style="color:#AA3CA7!important;" href="<?php echo the_permalink(); ?>"><?php echo the_title(); ?></a></h2>
<p class="news-page">
<?php $description = get_field('description');
echo substr($description,0,300) . "..." ?>
</p>
</div>
</div>
<?php endwhile; // end of the loop. ?>
</div>
<div class="clear"></div>
</div>
</div>
<?php get_footer(); ?>