Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How limit ”The Group Loop” to just the groups the user is a member of

  • Profile photo of admin25
    admin25
    Participant

    @admin25

    Hello,
    New to buddypress and coding.
    I need to limit “The Group Loop” to just the groups the user is a member of.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Profile photo of shanebp
    shanebp
    Moderator

    @shanebp

    Your answer is in the codex:
    https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-groups-loop/

    You need to pass the actual user id. Try this:

    
    loggedin_user->id ) ) : ?>
    
    Profile photo of admin25
    admin25
    Participant

    @admin25

    Hello shanebp, thanks for the response.

    I tried replacing the 1st line of code in the “groups loop”

    with your line of code
    loggedin_user->id ) ) : ?>
    but it still gives me all groups.

    Profile photo of shanebp
    shanebp
    Moderator

    @shanebp

    Try this:

    
    <?php
    global $bp;
    $user_id = $bp->loggedin_user->id;
    echo "user_id=" . $user_id;
    if ( bp_has_groups( 'max=20&user_id='  .  $user_id ) ) :
    ?>
    

    If $user_id echos a blank, then you have other problems in your file.

    Profile photo of admin25
    admin25
    Participant

    @admin25

    Thanks, that worked.

    Much appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] How limit ”The Group Loop” to just the groups the user is a member of’ is closed to new replies.
Skip to toolbar