Are you sure the search is powered by Relevanssi? That’s the first thing to check. If you disable Relevanssi, are the results different?
Hi, yes it is powered by Relevanssi. Made the test you’re suggesting and search results are changing.
I want to exclude a category from searching, I’m doing by category ID. But not working. As I told you is a Woocomerce category.
Also I tried to restrict the search to the categories I need, but still appearing the category I want to exclude.
Briefly I tell you how I configured Relebansvi:
I defined Relevanssi to just search products on “Choose post types to index:”
And deactivated fuzzy search. Also I defined some synonyms. Exclude category. Saved and build the index.
Thanks for support
I don’t know what a “WooCommerce category” is. The Relevanssi category exclusion works only for WordPress categories, ie. it needs to be the exact taxonomy “category”. If your categories are a different taxonomy, then that exclusion doesn’t indeed work.
If it’s a different taxonomy, what is the name of the taxonomy? If I know that, I can come up with exclusion code that’ll actually work.
Hi Mikko,
For product categories in Woocommerce taxonomy is:
product_cat
It good be great to have that exclusion. Is the only thing we need for the plugin to work perfect for our necessities.
Thanks
It’s probably better to do the exclusion on the indexing side of things in any case, as that gives some performance boost.
add_filter('relevanssi_do_not_index', 'rlv_exclude_cat');
function rlv_exclude_cat($exclude, $post_id) {
if (has_term( TERM, "product_cat", $post_id )) $exclude = true;
return $exclude;
}
where TERM is term name, slug or ID of the term you want to exclude, or an array if you plenty. Then rebuild the index, and you shouldn’t see the excluded category in the results.
Thanks for your support Mikko, the code worked as expected. Know we can exclude Woocommerce categories. Your plugin is a must! Congratulations
Cheers
Hi Mikko. Where your code has to be insert? Is the functions.php ok?