Home › Forums › Backend Issues (wp-admin) › Change Label in User Field Dropdown
Is there a way to customize the display of the user’s name in the User select box? I would like to show just the ‘Display Name’ instead of ‘username (display name)’ that is shown by default.
E.g., I would like this to just show ‘Matthew McVickar’:
You can use the “acf/fields/user/result” filter hook to do it. It’s not documented yet, but I believe you can do it like this:
function change_user_acf_result( $result, $user, $field, $post_id ) {
$result = $user->user_login;
if( $user->first_name ) {
$result = $user->first_name;
if( $user->last_name ) {
$result .= ' ' . $user->last_name;
}
}
return $result;
}
add_filter( 'acf/fields/user/result', 'change_user_acf_result', 10, 4 );
Hope this helps!
Sorry to revive this old thread, but it’s the only one that seems to relate directly to what I’m needing.
Similar to Matthew, I need to change the label shown in the admin dropdown. I have many different users with the same First/Last name, so it’s impossible to know which user is being selected. I’ve tried using the ‘acf/fields/user/result’ filter as James described, but it doesn’t appear to do anything. Was this filter removed?
Hi there,
I’m also after the exact thing. I need to display First/Last name and the email in the dropdown as some people have the same name.
If anyone finds a solution.
I just tested this, and that code worked just fine for me on a fresh installation of WordPress and ACF Pro:
Here’s the code I used:
function change_user_acf_result( $result, $user, $field, $post_id ) {
// Empty the string so we can repopulate it.
$result = '';
if ( $user->first_name ) {
$result .= $user->first_name;
}
if ( $user->last_name ) {
$result .= ' ' . $user->last_name;
}
if ( $user->user_email ) {
$result .= ' (' . $user->user_email . ')';
}
return $result;
}
add_filter( 'acf/fields/user/result', 'change_user_acf_result', 10, 4 );
You can see the result in the attached screenshot.
Hi Matthew,
Thanks for the help.. I bought the PRO plugin and this code is working now.
Not sure if I should start a new topic or not but would you know if there is a way to make the search in the dropdown search other fields (such as buddypress data?)…
Cheers
Ah, I’m glad it’s working now—apparently this functionality (or this filter?) is limited to Pro.
I would start a new topic for your other request… I don’t know anything about Buddypress, but the user dropdown wouldn’t search that data unless it saved them as actual WordPress users. Best of luck! 🙂
The topic ‘Change Label in User Field Dropdown’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.