• rjvv

    (@rjvv)


    Hi,

    I’m trying to have two different search forms: one for products and one for posts. I have this code (different search forms with different sesrch page templates:

    function wpb_search_filter($query) {
        if ( $query->is_search && !is_woocommerce() && !is_admin()) {
            $query->set( 'post_type', 'post' );
        }
          if ( function_exists( 'is_woocommerce' ) ) : 
            if ( $query->is_search && is_woocommerce() && !is_admin()) {
                $query->set( 'post_type', 'product' );
            }
        endif;
    
        return $query;
    }
    add_filter('pre_get_posts','wpb_search_filter');
    
    function template_chooser($template)   
    {    
      global $wp_query;   
      $post_type = get_query_var('post_type');   
      if( $wp_query->is_search && $post_type == 'products' )   
      {
        return locate_template('product-search.php');  //  redirect to archive-search.php
      }   
      return $template;   
    }
    add_filter('template_include', 'template_chooser');  

    It works fine with get_product_search_form(); but if I use [wcas-search-form] both of them will return only products.

    Any idea if this can be fixed while using the plugin?

    Thanks and keep up the good work.

    • This topic was modified 7 years ago by rjvv.
Viewing 1 replies (of 1 total)
  • Thread Starter rjvv

    (@rjvv)

    @damian-gora any tip on this or is this impossible? Does the pro version support both searches? I don’t want suggestions on the posts search, just want two different result pages, one with products and one with posts.
    thanks!

Viewing 1 replies (of 1 total)

The topic ‘Product Search and Post Search compatible’ is closed to new replies.