1

I use the get_product_search_form filter in replace of get_search_form, and I did changes in function.php file. But still I am not getting the solutions, Can anybody help me here Please.

If I search any products then I am getting such type of output: https://www.hickorydickorybox.com/?s=air+hover

But I want this: https://www.hickorydickorybox.com/?s=air+hover&post_type=product

2
  • modify the wp_query written on search.php
    – BlueSuiter
    May 8, 2017 at 10:57
  • We dont write WP_Query in search.php . Search.php automatically populates the latest 10 posts or page or CPT and displays it.
    – Aftab
    May 8, 2017 at 11:02

1 Answer 1

2

You can use 'pre_get_posts' filter hook and change the search query.

function wpse_search_filter( $query ) {
    if ( $query->is_search ) {
        $query->set( 'post_type', array('product') ); // setting post type as product (for woocommerce only)
    }
    return $query;
}
add_filter('pre_get_posts','wpse_search_filter');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.