Skip to:
Content
Pages
Categories
Search
Top
Bottom

question about Group filtering

  • Avatar of Chouf1
    Chouf1
    Participant

    @chouf1

    I have a BP site where i have private groups and public groups.

    Actually the “group” button on BP menu show’s all the groups, private and public, on the same page.

    I need to sort them by “status” or maybe “type”.

    This means for me a second button. So i would have a different button for each status.

    How can i filter the groups by status ?

    I searched but didn’t find something who can do this.

    And what is the page where i can see the private groups list ?

    Thanks !

Viewing 5 replies - 1 through 5 (of 5 total)
  • Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    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.

    Avatar of Mariusooms
    Mariusooms
    Participant

    @mariusooms

    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 );
    }

    Avatar of Chouf1
    Chouf1
    Participant

    @chouf1

    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…

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    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.

    Avatar of customwebdesignseo
    83 Oranges .com
    Member

    @customwebdesignseo

    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?

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.