First of all I am sorry if this is not the right place for a WordPress and WooCommerce question. But in the past I received a lot of help from this community so I decided to put my issue here.

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”.

Inside my custom built search.php I have checked current post_type inside the loop manually because I am dealing with mixed result from different post types.

My search.php file looks like the following:

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 for a product with a keyword which I know will pull up a product (the keyword I am using will not bring up any record from any other post type), the block if(have_posts()) is always returning false as if there is no post found.

  1. I looked at the URL and it appends post_type=product at the end fine.
  2. I checked Visibility option in Product edit page. Catalog/search option is selected by default already.
  3. I am not using “Relevanssi”.
  4. WordPress version: 4.7.3
  5. WooCommerce version: 2.6.14

Any help would be greatly appreciated!

Read more here: WooCommerce plugin: Products are not coming up in site search


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: