Support

Account

Home Forums ACF PRO Change the label for User Field

Solving

Change the label for User Field

  • Hello,

    Currently the User Field show up as Username (FirstName LastName).
    How can I have the value display as Username (FirstName LastName – email).

  • Using this filter you can alter the value that’s displayed in the user field, I don’t think these are documented anywhere but this is the code where they are applied in ACF

    
    $result = apply_filters("acf/fields/user/result", $result, $user, $field, $post_id);
    $result = apply_filters("acf/fields/user/result/name={$field['_name']}", $result, $user, $field, $post_id);
    $result = apply_filters("acf/fields/user/result/key={$field['key']}", $result, $user, $field, $post_id);
    

    These filters would work just like this filter http://www.advancedcustomfields.com/resources/acf-fields-relationship-result/

  • Here is an example for getting the E-mail (First name Last name) in the select user field.

    
    function alter_specific_user_field($result, $user, $field, $post_id) {
    
        $result = $user->user_email;
    
        if( $user->first_name ) {
            
            $result .= ' (' .  $user->first_name;
            
            if( $user->last_name ) {
                
                $result .= ' ' . $user->last_name;
                
            }
            
            $result .= ')';
        }
    
        return $result;
    }
    add_filter("acf/fields/user/result/key={field key here}", 'alter_specific_user_field', 10, 4);
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Change the label for User Field’ is closed to new replies.