Re: Trying to modify the group loop [SOLVED]
I think you might be barking up the wrong tree. Since you want to repurpose an existing query (the ‘my groups’ query) you don’t really need to alter the querystring. Instead, you should be altering the behavior of the query itself, which happens at the level of the bp_has_groups() function, as found in bp-groups/bp-groups-templatetags.php. One of the arguments for that function is user_id; when one is passed, you know you are looking at a my-groups loop.
Ideally, you would be able to filter bp_has_groups() to detect when a my-groups-type query was being requested, and then hijack it and do a query just for hidden groups. Unfortunately, I don’t believe that there is going to be an easy way to do that in this version of BuddyPress. For one thing, while there is a filter on bp_has_groups, the original arguments (like user_id) are not passed along to the filter in BP 1.2.7 (it’d be a good enhancement request). Second, there is no way to filter groups by status (public, private, hidden) at the moment (that too would be a good enhancement request).
One quick and dirty way to do something like what you want to do is to filter bp_has_groups, grab the content of the group query out of the groups_template global, and remove the ones that are *not* hidden. It’s not an ideal solution for a number of reasons (for one, it screws up pagination) but it can work. Here’s an example off the top of my head (untested!)
`function bbg_hidden_groups_only( $has_groups ) {
global $groups_template;
// when we are looking at a my-groups page…
if ( bp_is_user_groups() ) {
foreach ( $groups_template->groups as $key => $group ) {
if ( ‘hidden’ == $group->status ) {
unset( $groups_template->groups[$key] );
}
}
// reset the keys so you don’t end up with blank spaces
$groups_template->groups = array_values( $groups_template->groups );
}
return $has_groups;
}
add_filter( ‘bp_has_groups’, ‘bbg_hidden_groups_only’ );`