I would start by hooking a filter to bp_has_groups. The filter should loop through the results and unset the ones you don’t want to display, depending on what page you’re on. Thus, if you’re on a page where you only want to show public groups (as determined by, for instance, the content of $bp->current_action or $bp->action_variables, you would unset each member of the groups array for which bp_get_group_type() returned ‘public’.
Making group type an argument for bp_has_groups is a good idea for an enhancement.
I had previously (bp1.1.3) created something like the following function in my bp-custom.php to spit out the group status. Not sure how useful this is before the loop though. Maybe create a feature request in trac.
function the_group_type() {
echo get_group_type();
}
function get_group_type( $group = false ) {
global $groups_template;
if ( !$group )
$group =& $groups_template->group;
$type = $group->status;
return apply_filters( 'get_group_type', $type );
}
Thank you guys !
@boone
We tried, but unfortunally during construction, we arrived on “function get_newest” in bp-groups-classes.php
$limit is… the limit to use a filter for “status”…. Here we are in the BP core… and we are not motivated to redo BP….
@marius
i will experiment your code…finger cross…
This works for me.
function filter_groups_by_type_private( $a, $b ) {
$groups = $b->groups;
foreach( $groups as $key => $group ) {
if ( $group->status != 'private' ) {
unset( $groups[$key] );
$b->group_count = $b->group_count - 1;
}
}
$groups = array_values( $groups );
$b->groups = $groups;
return $b;
}
add_filter( 'bp_has_groups', 'filter_groups_by_type_private', 10, 2 );
Play around with the value ‘private’ to change what the function does.
It’s not perfect, because the pagination is not adjusted accordingly. You’d probably have to rebuild the core function in order to make pagination happen, since per_page gets passed right along to the database function. That’s why I say you might do well to write an enhancement ticket and submit it to trac.buddypress.org. In the meantime, though, this will set you in the right direction.
Hi Boone!
I used your code to show only Public groups on the groups directory page however my issue is that when people use the search box on the directory, even private groups show up! Can you please help me stop private groups from showing up in the search results as well?