Skip to:
Content
Pages
Categories
Search
Top
Bottom

Getting User’s Full Name from user_id


  • techguy
    Participant

    @crashutah

    I’m trying to find an easy way to get the name for a user without having to scroll through all the xprofile fields. This is easy if the user is logged in ($bp->loggedin_user->fullname), but in this case I want to get the name of a different user to that I can display it for the logged in user.

    I could use the WordPress functions to get the display_name:
    $user_info = get_userdata($referring_user_id);
    $referring_user = $user_info->display_name;
    But the display_name is just the username and not the value in the name field.

    Any ideas on how to get this?

Viewing 5 replies - 1 through 5 (of 5 total)

  • techguy
    Participant

    @crashutah

    I found this little function:
    $user_test = new BP_Core_User( $referring_user_id );

    Has the full name, but you still have to go through all the xprofile fields. Plus, is it ok to call the user info this way? Will it have problems down the line.

    Another option is to sync the display_name with the name in the BP profile field, but I’m not sure the best way to do that and that could be problematic if they make changes to the name later.

    Anyone else run into this issue?


    Jeff Sayre
    Participant

    @jeffsayre

    You’re making it more difficult than need be.

    Just use the function bp_core_get_user_displayname() found in bp-core.php. You can give it a userid and it will spit out the user’s fullname. Just make sure that you echo the output as follows:

    echo bp_core_get_user_displayname( $userid )


    techguy
    Participant

    @crashutah

    Thank you Jeff. I figured it would be something simple, but couldn’t find it. I tried all sorts of bp_core_get combinations and couldn’t find that one. Thanks!

    Thanks for this… still works great! Anyone know of a site with all the functions listed out for easy searching for things like this yet?


    techguy
    Participant

    @crashutah

    The best place is the codex: https://codex.buddypress.org/home/ but it still needs some more love. Little by little it’s getting better though. After that, the code is the best place to find it I guess.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Getting User’s Full Name from user_id’ is closed to new replies.
Skip to toolbar