This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Conditional search

#22229
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Well, this might be possible via using a custom code, but I am not sure. I did a bit of research, and constructed the custom code below. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

This code will exclude the current users role + the admin user roles. So when testing, if you are logged in as admin, you might not see any results. Please note that there is no guarantee that this will work properly in any case.

add_filter('asp_query_args', 'asp_exclude_roles_sp', 10, 1);
function asp_exclude_roles_sp($args) {
  $user_roles = wcmo_get_current_user_roles();
  $args['user_search_exclude_roles'] = array_merge(
    array('administrator'),
    $user_roles
  );
  return $args;
}

function wcmo_get_current_user_roles() {
   if( is_user_logged_in() ) {
     $user = wp_get_current_user();
     $roles = ( array ) $user->roles;
     return $roles; // This returns an array
   } else {
    return array();
   }
}