Support

Account

Home Forums Backend Issues (wp-admin) Not allowing users with the editor role to select themselves in user field

Solved

Not allowing users with the editor role to select themselves in user field

  • Hi Everyone,

    This is my first post on here so please let me know if I have done something wrong with this post.

    I am currently working on a project that has the ACF user field. However I want to edit the field so that if the user has an editor role, then they cannot select themselves from the user field. However I do want them to have the ability to select everyone else including other editors.

    I was wondering if this is possible and how would I do this if it is possible?

    Any help would be greatly appreciated. Thank you in advance for taking the time to read my post.

    Thanks.

  • There is an undocumented hook for the user field

    
    acf/fields/user/query
    acf/fields/user/query/name={$field_name}
    acf/fields/user/query/key={$field_key}
    

    This works just like the same hook for a relationship field that is documented here https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/.

    The arguments are those for the WP get_users() function https://codex.wordpress.org/Function_Reference/get_users, you can set the “exclude” argument to the current user and that should remove them from the list.

  • Hi John Huebner,

    Thank you so much for the help. It worked great.

    Many thanks,

    Mat

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Not allowing users with the editor role to select themselves in user field’ is closed to new replies.