Exclude products with specific category and user role from search result
-
Hello,
I would like to exclude certain WooCommerce products from appearing in the search for a specific user role only. I have got this code from another topic on this site, but it doesn’t include the user role restriction. Can you please help?add_filter( ‘relevanssi_indexing_restriction’, ‘rlv_exclude_category_x’ );
function rlv_exclude_category_x( $restriction ) {
global $wpdb;
$restriction[‘mysql’] .= ” AND post.ID NOT IN (
SELECT tr.object_id FROM $wpdb->term_relationships AS tr, $wpdb->term_taxonomy AS tt
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id
AND tt.term_id = 507 ) “; // replace X with the category ID
$restriction[‘reason’] .= ‘ In the wrong category’;
return $restriction;
}
- The topic ‘Exclude products with specific category and user role from search result’ is closed to new replies.