Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] bp_has_members( 'user_id=' not returning all friends


  • CatchThePigeon
    Participant

    @catchthepigeon

    Hi all,

    I use buddypress along with Custom Post Types (as tickets) to manage a social event platform where people can see which friends are going to each event.

    I use

    
    <?php
        $tickets = getTicketsForEvent(get_the_ID());
    ?>
    <div id="members-dir-list" class="members dir-list events-page-member-list">
    <ul id="members-list" class="block-grid three-up" role="main">
    <?php foreach($tickets as $ticket) {
        if ( bp_has_members( 'user_id=' . bp_loggedin_user_id() ) ) :
            while ( bp_members() ) : bp_the_member();
        $user_id = bp_get_member_user_id();
        if($user_id == $ticket["member"]) {  // $ticket["member"] is always the User ID - stored as post meta on ticket
            $nomembers = false;
            $nooffriends++;
            ?>
    <li>
    <div class="item-avatar">
    <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar( 'type=full&width=125&height=125' ); ?></a>
    </div>
    <div class="item member-info">
    <div class="item-title">
    <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
    </div>
    <?php do_action( 'bp_directory_members_item' ); ?>
    </div>
    <div class="clear"></div>
    </li>
    <?php }
        endwhile;
        endif;
        } ?>
    

    The problem is that certain people never turn up in the list… AND even more weird is that people who don’t turn up are different for each person viewing.

    For example I never see userID 1543 in the list attending where one of my co-admins can see 1543 but never sees 1665…

    Has anyone come across anything like this before?

Viewing 9 replies - 1 through 9 (of 9 total)

  • CatchThePigeon
    Participant

    @catchthepigeon

    *Selecting notify me via email


    shanebp
    Moderator

    @shanebp

    Using bp_has_members() in a foreach loop is a bad idea.

    Try something like this:

    $friend_ids = friends_get_friend_user_ids( bp_loggedin_user_id() );
    $matches = array();
    
    foreach($tickets as $ticket) {
       if( in_array( $ticket["member"], $friend_ids ) )
           $matches[] = $ticket["member"]; 
    }
    
    if ( bp_has_members( 'include=' . $matches ) ) :
    //etc

    CatchThePigeon
    Participant

    @catchthepigeon

    @shanebp Thanks a lot that seems to work much better, or at least when I print the $matches array it seems to gives me the right user ID results.

    It doesn’t seem to loop though when I pass it through though…

    if ( bp_has_members( 'include=' . $matches ) ) :
    while ( bp_members() ) : bp_the_member();

    do I need to do anything to the $matches array first?


    CatchThePigeon
    Participant

    @catchthepigeon

    have also just tried

    if ( bp_has_members( array(‘include’ => $matches))) : 
       while ( bp_members() ) : bp_the_member();
    

    No joy


    shanebp
    Moderator

    @shanebp

    Maybe $matches is an array of strings?
    Try:
    $matches[] = (int) $ticket["member"];


    CatchThePigeon
    Participant

    @catchthepigeon

    It seems to return a load of people who aren’t on either tickets or friend list for

    $MemImploded = implode(“,”, $matches);
        if ( bp_has_members( array(‘include’ => $MemImploded))) :
    

    OR

    
    if ( bp_has_members( array(‘include’ => $matches))) :
    

    and for
    if ( bp_has_members( 'include=' . $matches ) ) :

    It returns nothing unfortunately…


    CatchThePigeon
    Participant

    @catchthepigeon

    Just saw reply after post.

    Array ( [0] => 4112 [1] => 1543 [2] => 119 ) is the exact output of $matches so not sure where the issues are coming from…

    Do you happen to know if 'include=' is a recent parameter added to BP as I don’t think this version is the latest.


    shanebp
    Moderator

    @shanebp

    Whats happens with this?

    if ( bp_has_members( 'include=4112,1543,119' ) ) :


    CatchThePigeon
    Participant

    @catchthepigeon

    Right fantastic, so if ( bp_has_members( 'include=4112,1543,119' ) ) : returns the 3 correct members.

    So the way round it was a mixture of the two things I tried… Being the end of the day – particularly monday I just completely missed it!

    Instead of holding the values as an array you need to implode the list to follow the 'include= not the array(‘include’ => $matches)

    SOLUTION

    $MemImploded = implode(', ', $matches);
     if ( bp_has_members( 'include=' . $MemImploded ) ) :
        while ( bp_members() ) : bp_the_member();
    

    Thanks very much to @shanebp for your help with this.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] bp_has_members( 'user_id=' not returning all friends’ is closed to new replies.
Skip to toolbar