Site logo

Archived topic

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

1 reply · Started by Jaime on October 14, 2020

Viewing posts 1–2 of 2

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

Hi there,

Instead of this:

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

Do this:

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

Let us know :)

This archived topic is closed to new replies.