Skip to:
Content
Pages
Categories
Search
Top
Bottom

Profile Fields Loop

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;?>

Accepted Parameters

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

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') ) : ?>

Fetch all the profile data, even empty fieds and groups, for current user.

<?php if ( bp_has_profile('hide_empty_groups=0&hide_empty_fields=0') ) : ?>