The Profile Data Loop / bp_has_profile()

Codex HomeDeveloper DocsCustom BuddyPress Loops → The Profile Data Loop / bp_has_profile()

The profile data loop is the most complex out of all the custom BuddyPress loops. It’s actually two loops in one, the first is to loop through profile field groups, and the second to loop through profile fields in that profile field group.

Standard Loop

<?php if ( bp_has_profile() ) : ?>
  <?php while ( bp_profile_groups() ) : bp_the_profile_group(); ?>

    <ul id="profile-groups">
    <?php if ( bp_profile_group_has_fields() ) : ?>

      <li>
        <?php bp_the_profile_group_name() ?>

        <ul id="profile-group-fields">
        <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

          <?php if ( bp_field_has_data() ) : ?>
          <li>
            <?php bp_the_profile_field_name() ?>
            <?php bp_the_profile_field_value() ?>
          </li>
          <?php endif; ?>

        <?php endwhile; ?>
        </ul>
      <li>

    <?php endif; ?>
    </ul>

  <?php endwhile; ?>

<?php else: ?>

  <div id="message" class="info">
    <p>This user does not have a profile.</p>
  </div>

<?php endif;?>

↑ Top ↑

Accepted Parameters

The bp_group_has_profile() function will accept a number of parameters that will manipulate the data being returned.

  • user_id required

    The ID of the user you want to fetch the profile data for. This is required if you are outside a member profile URL (/members/andy/…)

    • Default value: false
  • profile_group_id optional

    By default all groups and all fields will be displayed. If you provide the ID of a profile field group, then only the fields in this group will be displayed.

    • Default value: false

↑ Top ↑

Advanced Usage

Fetch all the profile data for the user with ID 10.

<?php if ( bp_group_has_profile( 'user_id=10' ) ) : ?>

Fetch the profile data for fields in the profile group ID 2 for the user with ID 10.

<?php if ( bp_group_has_profile( 'user_id=10&profile_group_id=2' ) ) : ?>

Fetch the profile data for fields in the profile group ID 2.

<?php if ( bp_has_profile('profile_group_id=2') ) : ?>