Skip to:
Content
Pages
Categories
Search
Top
Bottom

question about Group filtering

  • Avatar of danbpfr
    danbpfr
    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 7 replies - 1 through 7 (of 7 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 danbpfr
    danbpfr
    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?

    Avatar of 3x7
    3×7
    Participant

    @3x7

    Is there any plugin available to filter the “public” and “private” groups?

    Dropdown or tabs?

    Thanks!

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    @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!

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

You must be logged in to reply to this topic.