Tell us what you are trying to do?
Basically I'm trying to duplicate a custom snippet for different parameters.
I have a custom post type called "Review" and within that post I want to create custom select fields to assign users to different job roles of that review based on their wordpress roles (defined my ultimate member).
There are 3 roles I want to add ......
Chair. UM Role: um_chair Custom Field Slug: list-of-users-chair
Expert by Experience. UM Role: um_expert-by-experience. Custom Field Slug: list-of-users-ebe
Independent Clinician. UM Role: um_independent-clinician. Custom Field Slug: list-of-users-ic
I've used the following threads for reference.
https://toolset.com/forums/topic/types-create-a-custom-field-and-have-a-dropdown-of-users-as-value/ (used for bulk of the code)
https://toolset.com/forums/topic/filter-by-author-for-only-custom-user-type/ (Used to add role filter)
Using the threads I created the first drop down select list with no issues using the following complete code ........
add_filter('option_wpcf-fields', 'fill_my_users');
function fill_my_users($fields) {
foreach ($fields as &$field) {
if ($field['id'] == 'list-of-users-chair') {
$field['data']['options'] = array();
$users = get_users( 'role=um_chair' );
foreach ($users as $user) {
$field['data']['options'][$field['id'] . $user->user_login] = array('title' => $user->user_firstname . ' ' . $user->user_lastname, 'value' => $user->ID);
}
}
}
return $fields;
}
My only issue is that I don't know how to replicate it for the other two roles (Expert by Experience and Independent Clinician). Can you help at all, can it all be done with one snippet or does it have to be separate snippets for the two other roles?
Cheers
Ed
Hello,
In your custom PHP codes, you are using function get_users(), see wordpress document:
https://developer.wordpress.org/reference/functions/get_users/#comment-content-2112
In the bottom of above page, there is an example codes to get multiple user roles:
...
get_users( [ 'role__in' => [ 'author', 'subscriber' ] ] );
...
For your reference.