I may be a late comer to this thread. I have created a custom search form and search result page for my website. The custom search form (searchform.php) looks like this:
<form role="search" method="get" action="<?php echo home_url('/') ?>" >
<input type="text" class="form-control" placeholder="Enter keyword to search..." value="<?php echo get_search_query(); ?>" name="s" title="Search" />
<input type="hidden" name="post_type[]" id="post_type" value="trips" />
<input type="hidden" name="post_type[]" id="post_type" value="package_tour" />
<input type="hidden" name="post_type[]" id="post_type" value="hotel-info" />
<input type="hidden" name="post_type[]" id="post_type" value="travelog" />
<input type="hidden" name="post_type[]" id="post_type" value="product" />
</form>
All other post_types are working fine and returning results except “product”.
And in search.php I have checked current post_type inside the loop manually because I have to deal with mixed result suppose to come from different post types.
if(have_posts()) {
global $wp_query;
while(have_posts()) : the_post();
$postType = get_post_type(get_the_ID());
if($postType == 'trips') {
//I am getting result
}
elseif($postType == 'travelog') {
//I am getting result
}
elseif($postType == 'product) {
// Not getting any result from product post_type.
}
endwhile;
}
When I am searching with a keyword which I know will not bring up anything else except one product, the block if(have_posts())
is not at all executing as if there is no post found at all.
I looked at the URL and it appends post_type=product
at the end fine.
I also checked Visibility option in Product edit page. The option Catalog/search is selected by default.
I am not using “Relevanssi”.
What is wrong in my approach?