Support

Account

Home Forums General Issues Print the Value of a User Field Type By get_post_meta()

Solved

Print the Value of a User Field Type By get_post_meta()

  • Hi,

    I have a situation where I need to get the value for a User Field type by get_post_meta() function. But when I used thisprint_r ( get_post_meta( get_the_ID(), 'author_name', false ) ); it just returned the ID like this Array ( [0] => 26 ) but I need to get the email/username etc. How could I get it?

    Thanks.

  • ACF stores and array of ID values for user field and does the work of getting all the user information when you use get_field(). If you need to use get_post_meta() then you’ll need to do all that additional work yourself. See https://codex.wordpress.org/Function_Reference/get_userdata

  • Thank you John, it’s solved.

    For anyone who is into a same situation. The below code did the work.

    
    $user_id = get_post_meta( get_the_ID(), 'author_name', true );
    $user_info = get_userdata($user_id);
    echo 'Email: ' . $user_info->user_email;
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Print the Value of a User Field Type By get_post_meta()’ is closed to new replies.