Home Forums Backend Issues (wp-admin) [field USER] Add email next to name on ajax results returned


[field USER] Add email next to name on ajax results returned

    • cedgef

    • February 17, 2021 at 5:49 am

    Hi everyone,

    I have custom fields on a specific type of posts.
    One of those fields is a type: User.
    It offers a dropdown with a search field that returns users.

    The results are shown like that :
    Firstname Lastname (nickname)
    Firstname Lastname (nickname)
    Firstname Lastname (nickname)

    I would like to add the email next to nickname.
    What would be the best way to do that?

    Thank you

  • There is a filter hook acf/fields/user/result, it is not documented, but it works the same as acf/fields/post_object/result

    • cedgef

    • February 18, 2021 at 8:27 am

    Thank you!
    For others here is what I did.

    add_filter('acf/fields/user/result', 'my_acf_fields_user_text', 10, 4);
    function my_acf_fields_user_text($text, $user, $field, $post_id){
        $args = array(
            'post_type' => 'MY_POST_TYPE',
            'order' => 'DESC',
            'posts_per_page' => 5,
            'paged' => 1,
            'meta_query' => array(  
                'relation' => 'AND',
                    'key' => 'user_name',
                    'value' =>$user->ID,
                    'compare' => '=',
                    'key' => 'META_TO_COMPARE',
                    'value' =>0,
                    'compare' => '=',
        $posts = new WP_Query( $args );
        $nb_posts = $posts->found_posts;
        $text .= ' - ' . $user->user_email .  ' [' . $nb_posts . ' posts]';
        return $text;
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

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.