Group Members Loop
The group members loop can be used to display members that have joined a group. It can be used nested inside the bp_has_groups() loop, or on its own with a group_id
parameter.
Standard Loop
<?php if ( bp_group_has_members() ) : ?> <div id="member-count" class="pag-count"> <?php bp_group_member_pagination_count() ?> </div> <div id='member-pagination' class='pagination-links'> <?php bp_group_member_pagination() ?> </div> <ul id="member-list" class="item-list"> <?php while ( bp_group_members() ) : bp_group_the_member(); ?> <li> <!-- Example template tags you can use --> <?php bp_group_member_avatar() ?> <?php bp_group_member_link() ?> <?php bp_group_member_joined_since() ?> </li> <?php endwhile; ?> </ul> <?php else: ?> <div id="message" class="info"> <p>This group has no members.</p> </div> <?php endif;?>
Accepted Parameters
The bp_group_has_members()
function will accept a number of parameters that will manipulate the data being returned.
-
group_id required
The ID of the group to fetch members for. Required when either: outside of the normal BuddyPress groups URL (/group/i-love-bp/members/) or not nested within a bp_has_groups() loop.
- Default value:
false
- Default value:
-
per_page optional
The number of members to display on a page before they are paginated to the next page.
- Default value:
10
- Default value:
-
max optional
The total number of members to return.
- Default value:
false
(no limit)
- Default value:
-
exclude_admins_mods optional
If you set this to true, only users with normal access (not a group administrator or moderator) will be returned in the members list.
- Default value:
true
- Default value:
-
exclude_banned optional
If you set this to true, any users that are banned from the group will not be returned in the members list.
- Default value:
true
- Default value:
Advanced Usage
Fetch all the members from the group with ID 15
and show 10
per page.
<php if ( bp_group_has_members( 'group_id=15&per_page=10' ) ) : ?>