How to Exclude a Group From the Loop in BuddyPress

How to Exclude a Group From the Loop in BuddyPress

One sure-fire way to exclude groups from the loop in BuddyPress is to set them as Private or Hidden in the admin settings.

However, if you need the group to be visible in the directory but not in a particular widget, then you’ll have to use a little hack for now.

One example would be if you’re using a group as a shell for a “global forum” and you want to exclude that group from a widget that displays popular groups. BuddyPress documentation for custom group loops doesn’t include a parameter for excluding particular groups, so here’s how you can do it:

<?php while ( bp_groups() ) : bp_the_group(); if(bp_get_group_name() != 'My Group' ) : ?>

Replace ‘My Group’ with the group name that you want to exclude. Also, don’t forget to add an endif; right before the endwhile;

<?php endif; ?>

Many thanks to nahummadrid and r-a-y at the BuddyPress forums for this quick hack.

Free Video Why 100 is NOT a Perfect Google PageSpeed Score (*5 Min Watch) Learn how to use Google PageSpeed Insights to set realistic goals, improve site speed, and why aiming for a perfect 100 is the WRONG goal.