BP 11: bp_has_profile() Now Accepts an Array of Profile Group IDs

In the upcoming BuddyPress 11.0 release, we’ve added some developer frosting 🧁 to make working with profile groups more straightforward. The template function bp_has_profile() and its underlying function BP_XProfile_Group::get() now accept a single profile group ID or an array of profile group IDs, making it easier to loop through your members’ profile data.

For example, the following code:

$profile_args = array(
    'user_id'          => 1,
    'profile_group_id' => array( 1, 2 ),

if ( bp_has_profile( $profile_args ) ) :
    while ( bp_profile_groups() ) : bp_the_profile_group();
        if ( bp_profile_group_has_fields() ) : ?>
            <h2><?php bp_the_profile_group_name(); ?></h2>

            <table class="profile-fields">

                <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

                    <?php if ( bp_field_has_data() ) : ?>

                        <tr<?php bp_field_css_class(); ?>>

                            <td class="label"><?php bp_the_profile_field_name(); ?></td>

                            <td class="data"><?php bp_the_profile_field_value(); ?></td>


                    <?php endif; ?>

                <?php endwhile; ?>



produces the following output:

Without having to add an extra profile group loop! You can test this new functionality out in the most recent BuddyPress v11 release beta.