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:
1 2 3 4 5 6 7
<?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
A slightly more complicated example is when you need to display fields such as checkboxes or drop-downs.
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:
1 2 3 4 5 6 7 8
<?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?
Sign up for more
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.