• Hello,

    I noticed with a custom plugin I’d built that my call to get all groups including hidden groups using BP_Groups_Group::get function that the sticky groups were filtered out but not added back in.

    My Code to get Groups;

    
    $bp_groups = BP_Groups_Group::get(
        array(
            'type'          => 'alphabetical',
            'show_hidden'   => true
        )
    );
    

    Looking into the code of this plugin it appears the sticky groups are filtered using the bp_groups_get_paged_groups_sql filter and then added back in using the groups_get_groups filter. This filter is applied through the groups_get_groups function which is an alias of BP_Groups_Group::get

    So in my case I can switch the function I utilize so that the groups_get_groups filter is executed to add back the sticky groups.

    Is it possible to amend this plugin to support the BP_Groups_Group::get approach? I’ve seen it used in several themes and plugins.

    Thank you

Viewing 1 replies (of 1 total)
  • Thread Starter Garrett Hyder

    (@garrett-eclipse)

    I ran into this issue again and took the time to find a workaround, shared below.

    To work around this Sticky Groups plugin I had to first get an instance of the BP_Sticky_Groups class so I could remove the bp_groups_get_paged_groups_sql and groups_get_groups filters then reapply them after doing the BP_Groups_Group::get function. See code example;

    $bp_sticky_groups = BP_Sticky_Groups::instance();
    remove_filter( 'bp_groups_get_paged_groups_sql', array( $bp_sticky_groups, 'alter_bp_groups_query'     ), 10, 2 );
    remove_filter( 'groups_get_groups',              array( $bp_sticky_groups, 'prepend_stickies_on_front' ), 10, 2 );
    $vgroups =  BP_Groups_Group::get(array(
    	'type'			=> 'alphabetical',
    	'per_page'		=> -1,
    	'show_hidden'	=> true
    ));
    add_filter( 'bp_groups_get_paged_groups_sql', array( $bp_sticky_groups, 'alter_bp_groups_query'     ), 10, 2 );
    add_filter( 'groups_get_groups',              array( $bp_sticky_groups, 'prepend_stickies_on_front' ), 10, 2 );

    Hope this helps others,
    Cheers

Viewing 1 replies (of 1 total)
  • The topic ‘Sticky Groups missing when using BP_Groups_Group::get function’ is closed to new replies.