Show members of members group

I want to show all members of the group in which the user is also member.
For this, I want to use the buddypress members loop:
http://codex.buddypress.org/developer/loops-reference/the-group-members-loop-bp_group_has_members/

As a permitted parameter, I try to get the group_id and start the members loop, but I always get the output “This group has no members.”:

global $bp;
 $group = groups_get_group( array( ‘group_id’ => $group_id ) );

if ( bp_group_has_members( '$group' ) ) : ?>


<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;?>

Related posts

Leave a Reply

2 comments

  1. Have you looked at
    function bp_group_has_members
    in
    buddypressbp-groupsbp-groups-template.php ?

    You can’t pass a string ‘$group’ to bp_group_has_members.

    Try:

    $this_id = bp_get_group_id();
    echo "group id is: " . $this_id;  // make sure there is a value here. 
    $has_members_str = "group_id=" . $this_id;
    if ( bp_group_has_members( $has_members_str ) ) 
    
  2. You can Show members of members group by using below code you just have to get id of group by using this method

    $group_id = bp_get_group_id();

    $group_id =  bp_get_group_id();
    if ( bp_group_has_members( $group_id  ) ): ?>
    <?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;