• This plugin could really use an equivalent of the “ignore_sticky_posts” argument in WordPress core. For me, it doesn’t really make much sense to have sticky posts in the groups widget, for example. In lack of a better way of achieving this, I came up with the following solution in my functions.php:

    if (class_exists('BP_Sticky_Groups') && !is_admin() ) {
    
    	remove_filter( 'bp_groups_get_paged_groups_sql', array( BP_Sticky_Groups::instance(), 'alter_bp_groups_query' ), 10, 2 );
    
    	function allow_sticky_groups() {
    		add_filter( 'bp_groups_get_paged_groups_sql', array( BP_Sticky_Groups::instance(), 'alter_bp_groups_query' ), 10, 2 );
    	}
    	add_action('bp_before_groups_loop', 'allow_sticky_groups');
    
    	function disallow_sticky_groups() {
    		remove_filter( 'bp_groups_get_paged_groups_sql', array( BP_Sticky_Groups::instance(), 'alter_bp_groups_query' ), 10, 2 );
    	}
    	add_action('bp_after_groups_loop', 'disallow_sticky_groups');
    
    }

    I hope that helps someone and/or maybe even encourages the plugin author to implement a neater solution. ??

    https://www.ads-software.com/plugins/bp-sticky-groups/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Sammy Nordstr?m

    (@samface)

    That didn’t work entirely as expected. As it turns out, you need to do it a bit differently to ignore sticky posts in Ajax requests as well. I ended up doing it as a plugin in order to hook into the right actions and filters, like this:

    <?php
    /*
    Plugin Name: BP Ignore Sticky Groups
    Description: A plugin to ignore sticky groups everywhere except on the groups page
    Version: 1.0
    Requires at least: 3.6
    Tested up to: 3.8
    Author: samface, angrycreative
    Author URI: https://angrycreative.se
    License: GPLv2
    Network: true
    Text Domain: bp-ignore-sticky-groups
    Domain Path: /languages/
    */
    function bp_ignore_sticky_groups() {
    	$bp =  buddypress();
    
    	if( bp_is_active( 'groups' ) && class_exists('BP_Sticky_Groups') ) {
    
    		if( empty( $bp->groups->extend ) )
    			$bp->groups->extend = new stdClass();
    
    		if( empty( $bp->groups->extend->bp_sticky_groups ) )
    			$bp->groups->extend->bp_sticky_groups = BP_Sticky_Groups::instance();
    
    		function allow_sticky_groups() {
    			if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
    				remove_action( 'bp_groups_get_paged_groups_sql', 'disallow_sticky_groups', 1, 1 );
    				add_filter( 'bp_groups_get_paged_groups_sql', array( BP_Sticky_Groups::instance(), 'alter_bp_groups_query' ), 10, 2 );
    			}
    		}
    
    		function disallow_sticky_groups( $sql = "" ) {
    			if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
    				remove_filter( 'bp_groups_get_paged_groups_sql', array( BP_Sticky_Groups::instance(), 'alter_bp_groups_query' ), 10 );
    				add_action( 'bp_groups_get_paged_groups_sql', 'disallow_sticky_groups', 1, 1 );
    			}
    			return $sql;
    		}
    
    		add_action( 'bp_before_groups_loop', 'allow_sticky_groups', 1 );
    		add_action( 'bp_after_groups_loop', 'disallow_sticky_groups', 1 );
    
    		add_action( 'bp_groups_get_paged_groups_sql', 'disallow_sticky_groups', 1, 1 );
    	}
    
    }
    
    add_action( 'bp_include', 'bp_ignore_sticky_groups' );

    Preferrably the Sticky Posts plugin would enable the site admin to choose when and where the sticky posts should be applied, but the above solution does the trick for me right now.

    hi @samface

    Thanks for your interest and for sharing, i’ll try to look at it more carefully as soon as i can.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Ignore sticky posts’ is closed to new replies.