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?
Is there any plugin available to filter the “public” and “private” groups?
Dropdown or tabs?
Thanks!
@3×7
Code changes all the time and resurrecting an old post is not good. You need to create a new topic because what may applied then may not apply now.
@mercime @hnla Can the site be adjusted to lock these old topics after a predetermined time interval so they are left just a reference point? We constantly repeat ourselves on this so it would be nice if there was an automated way to lock all of the old topics after a certain time period where when the moderators feel that the info is dated, then it requires the user to create a new topic instead of replying to old out of date info. Anything over a year to me is outdated but you have more experience in this than I. Anyway it is just an idea so don’t take it negatively. Thanks!