How To Display BuddyPress Profile Data On WordPress Multisite Blogs

How To Display BuddyPress Profile Data On WordPress Multisite Blogs

Displaying BuddyPress profile data outside of the main BuddyPress components is a little trickier than you might imagine. However, this is a common request, especially since many of our readers manage multisite networks. So for this quick tip we’re going to examine a few examples of displaying BuddyPress profile data on multisite blogs.

Basic Example of Displaying BP Profile Info on a Multisite Blog

A very common scenario is where you want to display an author’s bio on his multisite blog, pulling the content from a BuddyPress profile field. The code below gets the blog admin’s user ID and displays the profile field that you specify. You only need to replace the ‘Bio’ with the name of the field you’re trying to display:

{code type=php}
<?php
global $bp;
$thisblog = $current_blog->blog_id;
$user_id_from_email = get_user_id_from_string( get_blog_option($thisblog, ‘admin_email’));
$myfield = xprofile_get_field_data( ‘Bio’, $user_id_from_email );
echo $myfield;
?>

This works for any kind of basic text field and can be added anywhere within the blog’s theme templates.

Display Data From a Checkbox Profile Field on Multisite Blogs

Example of a checkbox profile field displayed on a multisite blog

A slightly more complicated example is when you need to display fields such as checkboxes or drop-downs.

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

I took a hint from a WordPress StackExchange post for displaying unserialized profile fields. The key is to use $multi_format = ‘comma’ to output your chexboxes or dropdowns.

In this example we’ll display a ‘Counties Served’ checkbox field with each county separated by a comma, using the following code on a multisite blog:

{code type=php}
<?php
global $bp;
$thisblog = $current_blog->blog_id;
$user_id_from_email = get_user_id_from_string( get_blog_option($thisblog, ‘admin_email’));
$myfield = xprofile_get_field_data( ‘Counties Served’, $user_id_from_email, $multi_format = ‘comma’ );
$data = xprofile_format_profile_field(‘checkbox’, $myfield);
echo $data;
?>

Here you’ll want to replace the ‘Counties Served’ with the name of the profile field you are wanting to display. Pretty simple, right?

There is an old plugin that does this and quite a bit more with easy-to-use widgets, but in this case I wanted something simpler. If any of you know a better way to show BP profile fields in mulitsite, please let us know in the comments.