We are trying to setup a search on a custom post type based on a custom field selection in the search form.
We can get it to work fine when no custom field is selected but it's not returning results when a custom field is selected.
The code for the search form looks like this:
<form role="search" action="<?php echo site_url('/'); ?>" method="get" id="searchform">
<div class="box">
<label for="search-text">Search</label>
<div class="search-fields">
<div class="search-text">
<input type="text" name="s" id="search-text"><input type="hidden" name="post_type" value="publication" />
</div>
<div class="search-in">
<div class="search-in-selected"></div>
<span class="arrow"></span>
<div class="search-in-dropdown">
<ul class="no-list">
<input type="radio" name="search-in" value="all" id="search-in-all" checked><label for="search-in-all">All</label>
<input type="radio" name="search-in" value="Article" id="search-in-article"><label for="search-in-article">Articles</label>
<input type="radio" name="search-in" value="News" id="search-in-news"><label for="search-in-news">News</label>
</div>
</div>
</div>
<div class="search-submit">
<input type="submit" name="submit" value="Search">
</div>
</div>
</form>
The code on our custom search page looks like this:
<?php
$search_in = $_GET['search-in'];
if ($search_in == "Article") {
$args = array( 'post_type' => 'publication', 'meta_query' => array(array('key' => 'wpcf-news_type', 'value' => 'Article', 'compare' => 'LIKE')), 's' => $s, 'showposts' => -1 );
}
else if ($search_in == "News") {
$args = array( 'post_type' => 'publication', 'meta_query' => array(array('key' => 'wpcf-news_type', 'value' => 'News', 'compare' => 'LIKE')), 's' => $s, 'showposts' => -1 );
}
else {
$args = array( 'post_type' => 'publication', 's' => $s, 'showposts' => -1 );
}
query_posts( $args );
$total_results = $wp_query->found_posts;
?>
What am I doing wrong when it comes to including the custom field wpcf-news_type?