• Hello All – I would like to make the search bar to search for post_type=product by default.. that way I show the product archive page rather than list of posts. How can I achieve that? Is there a configuration in the theme or is it a customisation? if latter, any guidance please?

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Hi there,

    Thank you for writing in,

    function searchfilter($query) {
     
        if ($query->is_search && !is_admin() ) {
            $query->set('post_type',array('product'));
        }
     
    return $query;
    }
     
    add_filter('pre_get_posts','searchfilter');

    Could you please use tthis above code in fuction.php file and try once.

    Regards!

Viewing 1 replies (of 1 total)
  • The topic ‘How to default search to post_type=product?’ is closed to new replies.