BP_Groups_Member::total_group_count( int $user_id )

Get the count of groups of which the specified user is a member.

Description

Parameters

$user_id

(Optional) Default: ID of the displayed user.

Return

(int) Group count.

Source

File: bp-groups/classes/class-bp-groups-member.php

781
782
783
784
785
786
787
788
789
790
791
792
793
794
public static function total_group_count( $user_id = 0 ) {
    global $wpdb;
 
    if ( empty( $user_id ) )
        $user_id = bp_displayed_user_id();
 
    $bp = buddypress();
 
    if ( $user_id != bp_loggedin_user_id() && !bp_current_user_can( 'bp_moderate' ) ) {
        return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    } else {
        return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    }
}

Changelog

Changelog
Version Description
BuddyPress 1.6.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.