• 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;
    }

Viewing 1 replies (of 1 total)
  • Plugin Author Mikko Saari

    (@msaari)

    That filter hook doesn’t work; it’s an indexing hook, so it applies to all searches.

    The correct tool is the relevanssi_post_ok hook, which can be used to control who sees which posts. There are lots of examples of the hook use in the Relevanssi knowledge base, see the link above.

Viewing 1 replies (of 1 total)
  • The topic ‘Exclude products with specific category and user role from search result’ is closed to new replies.