BuddyDev

Search

[Resolved] Display Buddypress users by amount of Followers

  • Participant
    Level: Enlightened
    Posts: 51
    Milo on #39044

    Hi Brajesh,
    As it appears you are the only one that is doing anything with the follow plugin by R-A-Y at all I thought I would ask you this. I am using the Youzify (Youzer) plugin and the FOLLOW plugin seems to work well with it. I would like to display a top list of my members based on the amount of followers that they have. Would this be hard to code?

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 19579
    Brajesh Singh on #39057

    Hi Milo,
    Thank you for the question.

    The BuddyPress followe does not seem to provide the functionality for top followed users. you may use following code for the same.

    
    /**
     * returns n number of top followed users.
     *
     * @param int $count number of entries requested.
     *
     * @return array
     */
    function buddydev_get_top_followed_users( $count = 5 ) {
    	global $wpdb;
    
    	$bp = buddypress();
    
    	return $wpdb->get_col( $wpdb->prepare( "SELECT leader_id, COUNT( leader_id ) as follow_count FROM {$bp->follow->table_name} WHERE follow_type = %s GROUP BY leader_id ORDER BY follow_count DESC LIMIT 0, %d", '', $count ) );
    }
    
    

    It will give you an array of user ids ordered by their following count. You can iterate and list as you need. It will be available as a shortcode/widget in our future release.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 51
    Milo on #39067

    Wow thank you very much Brajesh you are awesome.

  • Keymaster
    (BuddyDev Team)
    Posts: 19579
    Brajesh Singh on #39069

    Hi Milo,
    Thank you for the kind words.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 51
    Milo on #39071

    Hi Brajesh,

    I tried to make my own shortcode with this but I must have done something wrong. When I run the following code it simply returns the word… Aray … on the page and nothing else.

    I added this code to my functions file…

    /**
     * returns n number of top followed users.
     *
     * @param int $count number of entries requested.
     *
     * @return array
     **/
    
    function buddydev_get_top_followed_users( $count = 100 ) {
        
    	global $wpdb;
    
    	$bp = buddypress();
    
    	return $wpdb->get_col( $wpdb->prepare( "SELECT leader_id, COUNT( leader_id ) as follow_count FROM {$bp->follow->table_name} WHERE follow_type = %s GROUP BY leader_id ORDER BY follow_count DESC LIMIT 0, %d", '', $count ) );
    }
    
    add_shortcode('top_followers', 'buddydev_get_top_followed_users');

    I used this shortcode..

    [top_followers]

You must be logged in to reply to this topic.

This topic is: resolved