Home › Forums › General Issues › ACF User Field – Hide user roles from dropdown
I have a community website with frontend posting using ACF Forms. When a user creates a new post, I want them to be able to select another user on the network as a contributor, or co-writer for that post.
I have this working perfectly so far, and a user can use the ‘User’ field that’s set up as a multi select. I also have the user object rendering on the frontend which is great.
The only issue is on the dropdown, I can see a list of user roles that are assigned to that person. For security purposes, I would like it to show only users, and not user roles.
Currently it shows:
Administrator
- User 1
- User 2
Editor
- User 3
- User 4
I would like it to show:
- User 1
- User 2
- User 3
- User 4
I have read up on the user field and studied the settings, and I cannot see a way to disable this. How would I go about removing the user role from the dropdown field?
There isn’t any way to remove that in ACF. ACF returns a flat array only when searching or when when only searching a single role (or the user query only returns a single role).
The only way that this could possibly be accomplished would be to assign users that should appear to multiple roles and selecting to only show uses in a specific role.
I was worried that may be the case. I have limited it to user role, and used some CSS to hide the Role name from the dropdown.
.select2-container--default .select2-results__group {
display: none !important;
}
Hi there,
Aside of it being a security issue (where anyone who has access to the “ACF user field” knows which role other users belong to) this field is not working as good as you might think.
We’re developing plugin for WP which defines new roles (e.g. priv-subscriber, priv-editor, priv-admin) where we give WP users multiple roles to be able to access different parts of our ecosystem. So right now with 100 registered users (where each of them can have multiple roles like “editor” plus “priv-subscriber” plus “priv-editor”) each of them is repeated twice or three times.
Can’t we have user field where users are not listed under their roles and not repeated?
You must be logged in to reply to this topic.
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.