Skip to:
Content
Pages
Categories
Search
Top
Bottom

Listing the group members of current users groups


  • morgyface
    Participant

    @morgyface

    This took me many hours to resolve so I’m posting it here so that it may help anyone else in a similar situation.

    Basically I needed to list the members of the group the current user was a member of.

    It wasn’t easy.

    In my situation the user is only ever a member of one group so I pulled out the first(and last) ID from the array using current, if your user was potentially part of many groups you could create a sub loop using foreach.

    This is the final code:

    <?php
    $groupid = BP_Groups_Member::get_group_ids( get_current_user_id());
    $this_id = current($groupid[groups]); /* extracts the first group ID from the array */
    $has_members_str = "group_id=" . $this_id;
    if ( bp_group_has_members( $has_members_str ) )
    : ?>
    <?php while ( bp_group_members() ) : bp_group_the_member(); ?>
    <?php bp_group_member_name() ?>
    <?php endwhile; ?>
    <?php else: ?>
    <h2>You smell, you're not part of any groups.</h2>
    <?php endif;?>

    I hope this helps someone.

  • The topic ‘Listing the group members of current users groups’ is closed to new replies.
Skip to toolbar