BuddyDev

Search

Loop parameters

  • Participant
    Level: Enlightened
    Posts: 56
    Andy on #4361

    Hi Brajesh

    I previously asked if you knew how to create 2 custom loop filters ready to be used as loop parameter in bp_has_activities() / bp_has_members()
    – order members by most followers (for BP follow plugin)
    – order posts by most favorited.

    I found out how to do one of them, thought I would share it. Here is a short script by imath for most favorited posts:
    https://github.com/imath/bp-loop-filters/blob/master/bp-loop-filters.php (see bottom half)

    then you can use the ‘meta_query’ parameter on a custom activity loop, example:

    	// filter acivities in order from most favorited to least favorited
    	function my_filter_activity( $loop ) { 
    
    		if ( bp_is_current_action( 'custom-page'' )) {
    		
    			$args['meta_query'] = array(
    				array(
    					'key'     => 'favorite_count',
    					'value'   => 1,
    					'type'    => 'numeric',
    					'compare' => '>='
    				),
    			);
    		}
    
    		return $loop;
    	}
    	add_filter( 'bp_after_has_activity_parse_args', 'my_filter_activity' );

    All I need to do now is work out how to do the same for the Buddypress followers plugin to order members by most followed. Imath’s script I think will start off as a good template to working it out. If you ever work out how to do this one, please let me know.

  • Participant
    Level: Enlightened
    Posts: 56
    Andy on #4362

    I made a variable error with my code, this is the correct code:

    
    // filter acivities in order from most favorited to least favorited
    	function my_filter_activity( $loop ) { 
    
    		if ( bp_is_current_action( 'custom-page'' )) {
    		
    			$loop['meta_query'] = array(
    				array(
    					'key'     => 'favorite_count',
    					'value'   => 1,
    					'type'    => 'numeric',
    					'compare' => '>='
    				),
    			);
    		}
    
    		return $loop;
    	}
    	add_filter( 'bp_after_has_activity_parse_args', 'my_filter_activity' );
    
    • This reply was modified 8 years, 6 months ago by Andy.
    • This reply was modified 8 years, 6 months ago by Andy.
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #4397

    Hi Andy,
    Thank you for posting.

    The problem here is that the followers plugi does not store the number of following/followers in the user meta. If it did, we an use the similar code by just modifying

    ‘bp_after_has_activity_parse_args’ to ‘bp_after_has_members_parse_args’ and instead of using the favorite_count we could use the foolower/foilloing count.

    So, The first step towards achieveing your goal will be to store the count in usermeta whenever a follow/unfollow action takes place.

    Will you be able to handle that yourself or should I look in the plugin and assits you?

    Thank you
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved