Support

Account

Home Forums General Issues ACF User Field – Hide user roles from dropdown

Solved

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;
    }
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.