Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to Get User Profile Data

  • @enailor

    Participant

    During a recent project, I needed to get certain User Profile Data to be used. This was used outside any loops and not on the Profile page. Hopefully this will help others seeking the same information.

    To obtain the default data (such as User ID, User Login, ect) use the following:
    `global $bp;
    $the_user_id = $bp->loggedin_user->userdata->ID;
    $the_user_login = $bp->loggedin_user->userdata->user_login;`

    Userdata values include:
    ID
    user_login
    user_pass (this is encrypted MD5 Hash)
    user_nicename
    user_email
    user_url
    user_registered
    user_activation_key
    user_status
    display_name

    To get field data from extended profile fields for the current logged in user, use the following:
    `$the_first_name = bp_get_profile_field_data(‘field=First Name&user_id=’.bp_loggedin_user_id());
    /* Change field name to the one you added to the profile, or if you know the field’s #, you can use that instead. */
    `

    I do hope this helps someone else. It drove me nuts trying to track down the info, but after piecing bits of information together, I was able to get this figured out.
    Have fun!
    Ed

Viewing 8 replies - 1 through 8 (of 8 total)
  • @n3k0

    Participant

    Excelent… thats works fine, is i was looking for :D thansk a lot… online a cuestion, how i can display correctly date fields @enailor ???

    @mamb2b

    Participant

    Thanks a lot for this awesome topic. It helped me a lot …

    @trinzia

    Participant

    I would like to display data from Xprofile next to member’s comments.

    I added an Xprofile field for Location, and can show it in my theme:

    $bp_location = bp_get_profile_field_data(‘field=Location&user_id=’.bp_loggedin_user_id());
    echo $bp_location;

    This is showing the location of the logged in user, not the comment author.
    Any idea how I could show the Location field for each comment author? WP codex didn’t have comment-author-ID, and I wasn’t sure if BP uses the same IDs anyway.

    Thanks!

    @shanebp

    Moderator

    If you mean activity comments…

    $bp_location = bp_get_profile_field_data( 'field=Location&user_id=' . bp_get_activity_comment_user_id() );
    echo $bp_location;

    If you mean post comments, I think you need to create a custom comment display.
    Example: https://codex.wordpress.org/Function_Reference/wp_list_comments#Comments_Only_With_A_Custom_Comment_Display

    @trinzia

    Participant

    This is for customized comments on custom post types. The specific question is what user ID I would use, to display an xProfile field for each comment author.

    I found WP’s comment author name and link, but not ID. If I did manage to get the comment author ID somehow (haven’t managed that yet), would it work with BP’s fields?

    @shanebp

    Moderator

    >would it work with BP’s fields

    It should.
    You can always hard code an ID to find out.

    @trinzia

    Participant

    If anyone needs this snippet, here’s how I displayed ProfileX data in my theme’s comments.php. Inside your custom comments layout, add this:

    
    <?php
    $author_id = get_comment(get_comment_ID())->user_id;
    if (function_exists('bp_get_profile_field_data')) {
    	$bp_location = bp_get_profile_field_data('field=Location&user_id='.$author_id);
    	if ($bp_location) {
    		echo '<div class="authorinfo">'. $bp_location . '</div>';
    	}
    }
    ?>
    

    You will need to change ‘location’ to the name of your ProfileX field.
    Note that, if you allow users to comment who are not logged in, the $author_id will be zero.

    @mohammad-mursaleen

    Participant

    Thanks Trinzia!

    $user_id = bp_loggedin_user_id();
    $bp_city = bp_get_profile_field_data('field=City&user_id='.$user_id);

    This worked for me.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to Get User Profile Data’ is closed to new replies.
Skip to toolbar