apply_filters( 'relevanssi_user_indexing_args', array $args )

This filter hook filters the arguments to get_users() when indexing users.


(array) The get_users() argument array.

More information

When Relevanssi Premium indexes users, it uses get_users() to fetch all the users. By default, Relevanssi indexes all users or non-subscribers, depending on the user indexing settings.

Then Relevanssi loops through all the users, check each user with the relevanssi_user_index_ok filter hook and then indexes the users it can index.

You can use this filter hook to control which users Relevanssi includes in the index. The list of possible parameters can be found in WP_User_Query::prepare_query() documentation. The most useful ones are:

  • role, role__in, and role__not_in for user roles,
  • meta_key, meta_value, and meta_compare for custom fields,
  • exclude for excluding specific users.

This would exclude users with the user_department custom field set to accounting:

add_filter( 'relevanssi_user_indexing_args', function( $args ) {
  $args['meta_key']     = 'user_department';
  $args['meta_value']   = 'accounting';
  $args['meta_compare'] = '!=';
  return $args;
} );