I was wondering if there is a way I can change the order that the users are listing when using a user selector field. By default it is alphabetically by username as it is in the WP users listing. I am looking for a way to have them displayed by first or last name when using the ACF user selector?
Hi @nickfmc
Currently there is no filter to modify the $args
for the get_users
function. I’ll add this to the to-do as it should be an easy feature to add.
Thanks
E
Hi @nickfmc
Just wanted to let you know I have pushed an update to github containing a filter for the user field $args.
You can hook in and modify them like so:
<?php
function my_acf_user_query( $args, $field, $post_id ) {
// http://codex.wordpress.org/Function_Reference/get_users
$args['orderby'] = 'nicename';
return $args;
}
add_filter('acf/fields/user/query/name=CUSTOM_FIELD_NAME', 'my_acf_user_query', 10, 3 );
?>
You can also remove the /name=CUSTOM_FIELD_NAME
for this to run on all user fields.
Thanks
E
Thanks Elliot, your support is top notch! appreciate the follow up on this.