Filter Hidden Groups from the Groups Loop
- 
		Hello, Wanted to share my findings are they were a pain to find… 
 If you want to filter hidden groups from the Groups Loop you’ll have to add a filter hooking onto the groups_sql calls:
 // Hide Hidden Groups from the Groups Loop
 add_filter(‘bp_groups_get_paged_groups_sql’, array($this, ‘filter_hidden_groups_sql’));
 add_filter(‘bp_groups_get_total_groups_sql’, array($this, ‘filter_hidden_groups_sql’));
 * If you’re doing this from functions.php instead of a class you’ll want:
 add_filter(‘bp_groups_get_paged_groups_sql’, ‘filter_hidden_groups_sql’);
 add_filter(‘bp_groups_get_total_groups_sql’, ‘filter_hidden_groups_sql’);And Execute your filter method to inject and AND for status != ‘hidden’: 
 // Buddypress Filter Hidden Groups from Groups Loop
 function filter_hidden_groups_sql($sql) {
 $sql_parts = explode(‘WHERE’, $sql);
 $new_sql = $sql_parts[0] . “WHERE g.status != ‘hidden’ AND” . $sql_parts[1];
 return $new_sql;
 }This will filter the sql query retrieving groups to exclude any hidden groups making it so a Members Group Listing doesn’t have holes or invalid count numbers. Hope this is useful to someone, 
 Cheers
- The topic ‘Filter Hidden Groups from the Groups Loop’ is closed to new replies.