How to Display BuddyPress Profile Field Data In Multisite Blogs

I’m trying to display a BuddyPress xprofile field on a WordPress multsite blog. I thought this might do the trick but displayed_user doesn’t seem to work outside of BP? Is there an easy way to do this? I know there’s an old plugin that does it in a widget but I don’t really need all of that and would rather put this directly in the theme.

Here’s what I’ve tried within the theme on the multisite blog. This works with loggedin_user->id but of course what I’m shooting for is the profile data for the blog admin. Is that possible to fetch?

<?php 
global $bp;
$myfield = xprofile_get_field_data( 'Counties Served', $bp->displayed_user->id, $multi_format = 'comma' );
$data = xprofile_format_profile_field('checkbox', $myfield);
echo $data;
?>

Related posts

Leave a Reply

2 comments

  1. After playing around with it a bit more, here’s what finally worked for me:

    global $bp;
    $thisblog = $current_blog->blog_id;
    $user_from_email = get_user_by('email', get_blog_option($thisblog, 'admin_email'));
    $user_id = $user_from_email->ID;
    $myfield = xprofile_get_field_data( 'Counties Served', $user_id, $multi_format = 'comma' );
    $data = xprofile_format_profile_field('checkbox', $myfield);
    echo $data;
    
  2. The $bp->displayed_user->id returns the same id as the author id so when you are not inside a members loop or on a members page you have to get the user id using WordPress functions.

    <?php 
    global $bp, $post;
    $myfield = xprofile_get_field_data( 'Counties Served', $post->post_author, $multi_format = 'comma' );
    $data = xprofile_format_profile_field('checkbox', $myfield);
    echo $data;
    ?>