Role Select ACF filter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function roles_select( $field ) {
    $data = array('');
    $roles_obj = new WP_Roles();
    $roles_names_array = $roles_obj->get_names();
     
    if (!empty($roles_names_array)) { foreach($roles_names_array as $role_slug => $roles) {
        $data[$role_slug]     = $role_slug;
    } }     
 
    $field['choices'] = $data;
    return $field;
      
}
add_filter('acf/load_field/name=roles_select', 'roles_select');
Comments