[Support request] How To Remove Pages From Search Results But Now WooCommerce Products?

Home Forums Support How To Remove Pages From Search Results But Now WooCommerce Products?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1489047
    Jaime

    I am using the following code to remove the pages from my site search results:

    if (!is_admin()) {
    function wpb_search_filter($query) {
    if ($query->is_search) {
    $query->set('post_type', 'post');
    }
    return $query;
    }
    add_filter('pre_get_posts','wpb_search_filter');
    }

    It is working good and removing pages but products also… I want to keep the products…

    Please help me in this

    #1489233
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Instead of this:

    $query->set('post_type', 'post');

    Do this:

    $query->set('post_type', array( 'post', 'product' ));

    Let us know 🙂

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.