Home Forums General Issues User field – Filter and show only same role users Reply To: User field – Filter and show only same role users

  • There is an undocumented filter for the user field, most of the user field is not documented.

    Anyway, there is a filter that you can use to alter the results for the user field, here is where it’s called in the user field code

    $args = apply_filters("acf/fields/user/query",							$args, $field, $options['post_id']);
    		$args = apply_filters("acf/fields/user/query/name={$field['_name']}",	$args, $field, $options['post_id']);
    		$args = apply_filters("acf/fields/user/query/key={$field['key']}",		$args, $field, $options['post_id']);

    $args is the same as the arguments used in the WP function get_users(),

    In your filter you would get the current user roles and then alter the arguments to include only other users with the same role, I think with the “role__in” argument, but I’m not sure.

    Sorry I cannot be more specific, but I only know that the filter exists, I’ve never used it.