admin管理员组

文章数量:1389783

How to get users already joined group count by user-id or username in BuddyPress.

For example,

In the member listing page, in the members loop, I like to get users group count and display in the grid.

How to get users already joined group count by user-id or username in BuddyPress.

For example,

In the member listing page, in the members loop, I like to get users group count and display in the grid.

Share Improve this question asked Mar 2, 2020 at 22:19 Gnanasekaran LoganathanGnanasekaran Loganathan 1216 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To get the group count, use groups_get_user_groups. Find it in: buddypress\bp-groups\bp-groups-functions.php

In the members loop, the member id is provided via: bp_member_user_id()

You will need to check the member-loop template to find out how to hook into the loop. Or overload that template in your child theme and add a do_action wherever you want it.

Once you have a hook, use it to call something like this:

function get_group_count_for_member() { 

    $groups_for_member = groups_get_user_groups( bp_member_user_id() );

    echo 'Groups: ' . $groups_for_member['total'];

}

本文标签: users joined group count in buddypress