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

  • modify the wp_query written on search.php
    – BlueSuiter
    Commented 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
    Commented May 8, 2017 at 11:02

1 Answer 1


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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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