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:

{code type=php}

{/code}

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

{code type=php}

{/code}

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