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(), https://developer.wordpress.org/reference/functions/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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.