Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Show Group Member List on Group Directory


  • DKerrigan
    Participant

    @dkerrigan

    I’ve been having a bit of trouble trying to find a way to get the primary Group Directory (where all the groups are listed with the ability to join/leave) to list all of it’s members.

    I’m trying to make a company directory page where employees are divided up into their departments (groups) with their avatar, full name, and biographies shown.

    Here is an example of the structure I am looking for:

    • {GROUP} Department 1
      • {AVATAR} JohnDoe.jpg
        {FULL NAME} John Doe
        {BIOGRAPHY} John really likes BuddyPress.
      • {AVATAR} JaneDoe.jpg
        {FULL NAME} Jane Doe
        {BIOGRAPHY} Jane really likes BuddyPress too!
    • {GROUP} Department 2
      • {AVATAR} JohnDoe.jpg
        {FULL NAME} John Doe
        {BIOGRAPHY} John really likes BuddyPress.
      • {AVATAR} JaneDoe.jpg
        {FULL NAME} Jane Doe
        {BIOGRAPHY} Jane really likes BuddyPress too!
Viewing 12 replies - 1 through 12 (of 12 total)

  • shanebp
    Moderator

    @shanebp

    In theme/groups/groups-loop.php there is a hook you can use:
    do_action( ‘bp_directory_groups_item’ );

    Use it to call a function that loops thru the members for that group.


    DKerrigan
    Participant

    @dkerrigan

    Thanks for the quick reply @shanebp.

    I tried using:
    `if ( bp_group_has_members() )`

    However, when I check out the Groups directory, each group has the message “This group has no members”. Is there any way to pass the group_id to bp_group_has_members() without hard coding it?


    shanebp
    Moderator

    @shanebp

    You don’t say where you tried to use bp_group_has_members().

    In a function you probably need a global or two, at least global $bp;

    Try hard coding a group_id into your bp_group_has_members() call.
    If that works, then you have to dig around and find the right globals and calls to make.
    ( maybe bp_get_current_group_id() ? )

    If it doesn’t work, there could be an issue with your setup or maybe you can’t use multiple
    bp_group_has_members calls in the same parent loop.
    According to the codex, the latter shouldn’t be an issue, but… ?
    https://codex.buddypress.org/developer/developer-docs/loops-reference/the-group-members-loop-bp_group_has_members/
    “The ID of the group to fetch members for. Required when… not nested within a bp_has_groups() loop.


    DKerrigan
    Participant

    @dkerrigan

    Thanks again for the help @shanebp.

    Here is a copy of the code in question: http://pastebin.com/J5sEfVNt

    When I hard code a group_id into Line 15, I can see members appear. However, I need it to be dynamic, as I want each group to show all members.


    DKerrigan
    Participant

    @dkerrigan

    I figured it out!

    Here is my new line 15 (php tags stripped out so you can see them here):
    `if ( bp_group_has_members( ‘group_id=’.bp_get_group_id().’&exclude_admins_mods=false’ ) ) :`


    shanebp
    Moderator

    @shanebp

    Untested but try http://pastebin.com/BVTHyuEL

    [
    edit: too late, but same solution you came up with… congrats
    It should work, from codex page, without the bp_get_group_id() call.
    Made a note on that page.
    ]


    DKerrigan
    Participant

    @dkerrigan

    @shanebp For whatever reason, the lines 27-38 that pull in member biographies are not working. No user biographies are being returned (the code works on the Members Directory, not the Groups). Any clue what is going on there?

    You are awesome by the way @shanebp. Really, really appreciate you helping me out.


    shanebp
    Moderator

    @shanebp

    Use:
    $bio = xprofile_get_field_data( ‘field=Biography’, $member_id );
    echo $bio; // may not need to echo

    Grab the $member_id from the members loop, maybe bp_get_member_user_id() ?


    DKerrigan
    Participant

    @dkerrigan

    @shanebp I still can’t get the bios to show.

    You can see my modified code here: http://pastebin.com/XP4SUFYi

    Lines 59-61 are what gets the Member ID (currently printing out on screen as confirmation).

    Lines 63-66 is the code block you gave me to implement, but it is not displaying any bios.


    DKerrigan
    Participant

    @dkerrigan

    (Sorry, I realized I was sourcing my Text Editor’s line numbers in my previous post)

    Figured it out!

    Here is the working code: http://pastebin.com/pHAcNwq9

    Line 24-26 grabs the User IDs. I had to replace bp_group_member_id() with bp_get_group_member_id(). bp_group_member_id() was echoing out the ID number and not passing any value to the bio function.

    Line 28-31 displays the Biography profile field.


    Chef
    Participant

    @splendidangst

    How would I go about displaying the Group tab with number of members (as it is in the nav tab) next to the profile avatar?


    wolsi
    Participant

    @wolsi

    So I’m rather new at WordPress so I think I’m missing something. I would like to accomplish basically the same thing as DKerrigan, not showing the bio field but some others. I think I can just reuse that code and change the field I want to be shown but where should I put that code? I thought I had to change groups-loop.php with the new code but that does not seem to do anything.

    Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] Show Group Member List on Group Directory’ is closed to new replies.
Skip to toolbar