I'm using "Instant Search & Suggest" wordpress plugin.

Let me give an example so it will be clear. So let's suppose that I have 2 custom post types: products and suppliers. For example, when I'm in products page (there I have search form), I'm starting to type one of the supplier post name and in suggestions I see searched supplier post name. But it shouldn't work like that. If I'm in products page and search something, it should search only in products and show suggestions only for products post type. And vise versa, if I'm in suppliers page and search something, it should search only in suppliers and show suggestions only for suppliers post type.

I tried to achieve that by adding below code in my functions.php file but it didn't help:

function searchFilter($query) {
    $post_type = $_GET['post_type'];
    if (!$post_type) {
            $post_type = 'any';
    if ($query->is_search) {
        $query->set('post_type', $post_type);
    return $query;


$_GET['post_type'] - In both pages (products, suppliers) I have search forms and each form differs from others with below hidden field (I've added hidden field with corresponding post type name):

<input name="post_type" type="hidden" value="products" />

Is there someone who could achieve to what I want?

Your Answer

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

Browse other questions tagged or ask your own question.