@vgrch– The role parameter sets which user role can see the field. So if you set it to “administrator”, and the logged in user is an “editor”, the field won’t display.
I’m assuming you are basing your field off this tutorial >
If so, then the WordPress function get_users() is what is actually generating the user list. get_users() has a role parameter that you can use. Based on that tutorial, you would modify your code to look like this:
piklist('field', array(
'type' => 'select'
,'field' => 'my_users'
,'label' => 'Choose a user'
,'attributes' => array(
'class' => 'text'
)
,'choices' => array(
'' => 'Choose User'
)
+ piklist(
get_users(
array(
'orderby' => 'display_name'
,'order' => 'asc'
,'role' => 'author' // Only show authors in this select field.
)
,'objects'
)
,array(
'ID'
,'display_name'
)
)
));
Let us know if you need any more help.