Support

Account

Home Forums General Issues Get value from User ID to Display Name?

Solved

Get value from User ID to Display Name?

  • Hi all,

    I have used ACF for create new fields name: “Author”, “Source”, and “Editor”:

    null

    null

    I picked fields in post editor:

    null

    And this code to show them:

    <?php
    $author = get_post_meta($post->ID, 'author', true);
    if ($author) { ?>
    Author: <? echo $author; ?><br />
    <?php
    } else {
    // do nothing;
    }
    ?>
    <?php
    $source = get_post_meta($post->ID, 'source', true);
    if ($source) { ?>
    Source: <? echo $source; ?><br />
    <?php
    } else {
    // do nothing;
    }
    ?>
    <?php
    $editor = get_post_meta($post->ID, 'editor', true);
    if ($editor) { ?>
    Editor: <? echo $editor; ?><br />
    <?php
    } else {
    // do nothing;
    }
    ?>

    But when they show on post, just user ID, look like this:

    null

    How can I get the User Display Name for that ID?
    Please help me!

    Thanks all.

  • You’re using get_post_meta() instead on get_field(). ACF only stores the user ID, so this is what will be returned by get_post_meta(). If you use get_field() ACF will return a user object, array, or ID depending on your field settings. In either case you need to get the user object and show the parts of it you want. https://codex.wordpress.org/Function_Reference/get_userdata

  • I fixed it done. Thanks Mr. Huebner so much 👍

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Get value from User ID to Display Name?’ is closed to new replies.