Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Filter Hidden Groups from the Groups Loop

@garrett-eclipse

Participant

Update – Found an issue with my code when you go to the second page of the Members Groups list it reverts to showing hidden, etc. This is due to the call being done with AJAX which is considered an admin so !is_admin is false. To correct this I’ve updated the if statement to check if DOING_AJAX:

// Buddypress Filter Hidden Groups from Groups Loop
function filter_hidden_groups_sql($sql) {
	if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)){
        $sql_parts = explode('WHERE', $sql);
        $new_sql = $sql_parts[0] . "WHERE g.status != 'hidden' AND" . $sql_parts[1];
	    return $new_sql;
	} else {
		return $sql;
	}
}

Basically this allows the backend admin to list all groups but the front end hides the hidden ones.

Cheers

Skip to toolbar