← back to code snippets

BuddyPress - all profile groups on one page

Posted on June 28th, 2015 in WordPress by Graeme

At the top of edit.php (yourtheme/buddypress/members/single/profile/edit.php), find this bit near the top:

if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) :
	while ( bp_profile_groups() ) : bp_the_profile_group();

The important part in the snippet above is this function call: bp_get_current_profile_group_id(). That grabs the current group ID from the URL, and sets it for the rest of the page. We want to change that bit.

Just above the first code snippet I wrote, paste this query to collect all the profile groups into one variable:

$sqlStr = "SELECT *idFROMwp_bp_xprofile_groups`”;
$groups = $wpdb->get_results($sqlStr);`

Now you can replace bp_get_current_profile_group_id() with this: $groups[0]

That will leave you with this:

if ( bp_has_profile( 'profile_group_id=' . $groups[0] ) ) :
	while ( bp_profile_groups() ) : bp_the_profile_group(); ?>

Now if you visit any of your edit profile group links, you’ll see all the groups on a single page.

Next, you will probably want to remove the pagination from the page, as it will get included multiple times (since we’re in a while loop), and it is also unnecessary now that we’re showing all groups on one page.

Remove this bit:

<ul class="button-nav">
   <?php bp_profile_group_tabs(); ?>