Skip to:
Content
Pages
Categories
Search
Top
Bottom

Group Types option display


  • danbp
    Moderator

    @danbp

    i need some advice or help about the following function. (i use BP 2.7 RC2)

    While it display correctly a list of all typed groups, i want also that all different types stays together.

    The list is sorting by alphatetical order group names as expected, but it seems more logic to get such a list sorted by types first – as we use a cutom group directory filter “by types”

    To be clear, what i expect it this when i click on Order by: Types

    Type A
    – group 1
    – group 2

    Type B
    – group 1 (has 2 types allocated)
    – group 3
    – group 4

    Type C

    and so on.

    I’m unable to add any array sort (or better i don’t know how to write the correct one) for this. I also haven’t found a BP filter (if exist)…

    If somebody could tell me how to achieve this, it would be great ! (@boonebgorges, @r-a-y, @ ….)

    // add a filter option on group directory
    function bpex_group_order_options() {    
        if( bp_is_active( 'groups' ) && bp_is_groups_directory() ) {
    ?>
    	<option value="gtype"><?php  _e( 'Types', 'buddypress' ); ?></option>
    <?php
    	}
    }
    add_action( 'bp_groups_directory_order_options', 'bpex_group_order_options' );
    
    // my problem is with this function:
    
    //ajax query for group types
    function bpex_group_types_filter_ajax_querystring( $querystring = '', $object = '' ) {
       
        if( $object != 'groups' )
            return $querystring;
    
        $defaults = array('type' => 'active' );
     
        $bpex_querystring = wp_parse_args( $querystring, $defaults );
     
        if( $bpex_querystring['type'] != 'gtype' )
            return $querystring;
           
        // query types
        $q_types = bp_groups_get_group_types();   
    
        $bpex_querystring = array( 'group_type' =>  $q_types );
        $bpex_querystring['type'] = 'alphabetical';
    
        return apply_filters( 'bpex_gtq_filter_ajax_querystring', $bpex_querystring, $querystring );
    
    }
    
    add_filter( 'bp_ajax_querystring', 'bpex_group_types_filter_ajax_querystring', 20, 2 );

    For those interested by extending their group directory for types, i wrote a tutorial (in french) with all snippets to get a tab for each type, displayable on the main group nav or on the new group type nav bar.

    If you use the tabed types display, you don’t really need a the filter option to check only for typed groups. But if you don’t want tabs more tabs, by lack place or whatever, you may want to access them via the group directory filter.

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

  • Henry Wright
    Moderator

    @henrywright

    Hi @danbp

    What exactly does bp_groups_get_group_types() return? Can you var_dump it and paste here?


    danbp
    Moderator

    @danbp

    Hi @henrywright

    it returns the type names

    array (size=3)
      'team' => string 'team' (length=4)
      'ninja' => string 'ninja' (length=5)
      'jaguar' => string 'jaguar' (length=6)

    Henry Wright
    Moderator

    @henrywright

    What happens if you sort those before assigning them to the group_type key?


    danbp
    Moderator

    @danbp

    @henrywright

    Nothing ! I can sort them, but i was unable to assign them correctly. Whatever i tried until yet, didn’t work. It’s like the default group filters keep precedance. My feeling about group type, is that it is implemented to be used inside of group create step first and in a single group as second. In brief, it’s an information for single groups.

    Also, this curious slug (groups/groupname/type/typename/) applied to the group type name showing up on a group header. This pseudo ‘type’ sub-page is used to display a directory of groups using the same type. But this directory isn’t the site group directory !
    Despite this, the default group nav menu is also on that page. And when you click for example on All Groups (the default group directory page) you remain on /groups/groupname/type/typename/. Bad UX !

    That’s what i discovered after unpacking 2.7 RC2. I opened a ticket and Ray patched it a few hours later. Seems to resolve partialy that specific menu problem, but for the moment it’s only a patch and a bug- not the final solution.

    Now, add to that issue, the fact that the group directory is ajaxified, that groups sort options have apparently priority whatever you add as custom option and also the (imho) complex way groups_get_groups applies his filters is far away from what i’m able to do. The mangle of doc and use examples related to types is also an obstacle.

    There is most probably a filter missing. The question is: what, how and where to apply it. Do we use bp_ajax_query_string or groups_get_groups ? Or both or something other ?

    That said, my low php knowledge is probably the first obstacle. ๐Ÿ˜‰ If you have a brilliant idea to surround this, don’t hesitate to share.
    I you want i can send you a copy of what i’m trying to do, bundled as plugin.


    Henry Wright
    Moderator

    @henrywright

    Instead of filtering ajax_querystring, how about using bp_parse_args()?

    Ref https://buddypress.trac.wordpress.org/browser/tags/2.2.1/src/bp-groups/bp-groups-template.php#L431


    Boone Gorges
    Keymaster

    @boonebgorges

    Hi @danbp – Sorry to hear that you’re having issues with the Group Type functionality. Your posts contain a couple different comments and questions, which I’ll try to address separately.

    First: An orderby=group_type parameter sounds like an interesting enhancement idea. It’d possibly be even more interesting if we could “group” results by type, but our group loops aren’t easily set up for that.

    Group type data is stored in the WP taxonomy tables. This decision was made because groups are in are many-to-many correspondence with types: a group can have multiple types, and a type can have multiple groups. But it does make it difficult to sort by type, both technically and conceptually. Technically, WP itself doesn’t natively allow sorting by taxonomy term for posts. Conceptually, if a group belongs to more than one type – say, ‘aaa’ and ‘zzz’ – it’s not clear where in the alphabetical order it should go.

    That said, if you really wanted to sort by type, you could do it by filtering the group query SQL, and joining against the term_relationships and term_taxonomy table. The query would have to look something like this:

    SELECT ... JOIN $wpdb->term_relationships tr ON (tr.object_id = g.id) JOIN $wpdb->term_taxonomy tt ON (tt.term_taxonomy_id = tr.term_taxonomy_id) WHERE ... tt.taxonomy = 'bp_group_type' ... ORDER BY tt.name

    > And when you click for example on All Groups (the default group directory page) you remain on /groups/groupname/type/typename/. Bad UX !

    For 2.7, we’re disabling AJAX for these queries, because of these UX concerns. Thanks for reporting the issue.

    > My feeling about group type, is that it is implemented to be used inside of group create step first and in a single group as second. In brief, itโ€™s an information for single groups.

    As I see it, the issue here is that you’re trying to combine grouping-by-type with the groups loop. Your use case is valid, but I don’t think it’s the only, or even the primary, use of group types. Just having the ability to filter by group type (example.com/groups/type/foo) is very useful for many implementations.

    Thanks for sharing your thoughts – it’s really helpful as we continue to improve the group types feature.


    danbp
    Moderator

    @danbp

    Thank you for these clarifications @boonebgorges

    What you’re saying confirms point by point what i discovered while trying to built a custom group directory.
    The sql trick (thank you for the syntax!) was my ultimate option to achieve it. But the price for this is – IMHO – too high in the actual group type stage.

    I won’t go this route simply for an order option display. And as you note, it may become confusing anyway if a group has more than one type assigned.

    In my project, i have already all types as tab with a correct sort order. With this configuration i don’t need a type option (already explained in my previous post). And anything is happening on the same URL /site/groups.

    But i added an option to show only groups having types. Ok, it is not grouped by types, but at least, i can see all typed group ONLY.

    Adding colors helped me to see what’s going on – semantically discutable – but i was just testing, not seeking for a AAA award. By the way, it is possible to do, in case of a perticular need. ๐Ÿ˜‰

    This remark struggles me a bit:
    Your use case is valid, but I donโ€™t think itโ€™s the only, or even the primary, use of group types.

    I don’t think that too ! But still now, i’m very unsure what a primary or other use case is. ๐Ÿ˜‰

    Here a screen shot of my group directory.

    Group Directory with tabed types display


    alexlii
    Participant

    @alexlii

    Great
    This is quite typical application, I know there is no category support by bp default, so it would be much great if “type” work as category, any plan to develop an plugin to do that?

    Alex


    pandraka
    Participant

    @pandraka

    @danbp Thank you for the tutorial. My group tabs worked perfectly until the last update of BuddyPress. Now the first time the page is loaded the tab displayed is correct. But If I switch tabs then all my tabs show all the groups. I am at a loss. Any ideas?


    pandraka
    Participant

    @pandraka

    I think this a bigger issue. I just removed my tabs, and went with the default groups, my groups and create. the my groups options displays all the groups too. This seems to be an bug with buddypress.


    Venutius
    Moderator

    @venutius

    Yes this issue has been reported:

    https://buddypress.trac.wordpress.org/ticket/8067


    pandraka
    Participant

    @pandraka

    @venutius Thank you. Do you know when version 4.3 will be released?


    Venutius
    Moderator

    @venutius

    It’s not been announced yet

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.
Skip to toolbar