Skip to main contentSkip to footer

Restricting the indexing to particular user roles

From the Relevanssi settings, you can only choose whether subscribers are indexed or not.

If you need finer control over what user roles are indexed by Relevanssi, you can use the relevanssi_user_index_ok filter hook with the following code. Place it in your theme functions.php:

add_filter( 'relevanssi_user_index_ok', 'rlv_do_not_index_admins', 10, 2 );
function rlv_do_not_index_admins( $do_index, $user ) {
  $block_these_roles = array(
    'administrator',
    'editor',
    'author',
    'contributor',
    'subscriber'
  );
	
  $vars = get_object_vars( $user );
  if ( is_array( $vars['caps'] ) ) {
    foreach ( array_keys( $vars['caps'] ) as $role ) {
      if ( in_array( $role, $block_these_roles, true ) ) {
        $do_index = false;
        break;
      }
    }
  }
  
  return $do_index;
}

Just adjust the $block_these_roles array to include the roles you want to exclude from the index.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

WooCommerce: Hidden products in search

…best way is to unindex the products so that they don’t appear in the index at all. How that is done, depends on the version of WooCommerce and Relevanssi you’re using. Relevanssi 4.0.9 / Premium 2.1.5 and WooCommerce 3 Versions 4.0.9 and 2.1.5 introduced a better way to block excluded……want to block from the search to true. Older Relevanssi versions and WooCommerce 3 WooCommerce 3 uses taxonomy terms to handle visibility. You can create a relevanssi_do_not_index filter function for these: add_filter( ‘relevanssi_do_not_index’, ‘rlv_wc3_hidden_filter’, 10, 2 ); function rlv_wc3_hidden_filter( $block, $post_id ) { if ( has_term( array( ‘exclude-from-catalog’, ‘exclude-from-search’, ‘outofstock’…Relevanssi by default shows out-of-stock and excluded from catalogue WooCommerce products in the search results, but hides those set to excluded from search (before 2.2.2 and 4.1.2 the default behaviour was to show all products). It is quite easy to make Relevanssi not display hidden products in the results. The…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed