BuddyDev

Search

[Resolved] Display total number groups of the logged in user

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #11864

    Hello, I would love to show how many buddypress groups a user has joined using a shortcode. Can anybody please help?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #11866

    Hello Mwale,

    Thanks for posting here. Use the following code to print the total number of groups current user is a member of or you can say the user has joined.

    
    function buddydev_print_user_total_groups() {
    
    	if ( ! is_user_logged_in() ) {
    		return '';
    	}
    
    	$groups = groups_get_groups( array(
    		'user_id' => get_current_user_id(),
    	) );
    
    	if ( empty( $groups ) ) {
    		return '';
    	}
    
    	ob_start();
    	echo 'Total Joined Groups: ' . $groups['total'];
    	return ob_get_clean();
    }
    add_shortcode( 'buddydev_user_total_groups', 'buddydev_print_user_total_groups' );
    

    Put this code into your ‘bp-custom.php’ file and use shortcode [buddydev_user_total_groups]

    Thanks
    Ravi

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #11869

    Hello Ravi,

    That’s exactly what I needed! Thank you so much!!! Buddydev is awesome..

    Kind Regards,
    Mwale

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #11870

    Hello Mwale,

    Thank you for this acknowledgement. I am glad that I could help.

    Regards
    Ravi

The topic ‘ [Resolved] Display total number groups of the logged in user’ is closed to new replies.

This topic is: resolved