Skip to:
Content
Pages
Categories
Search
Top
Bottom

Conditional Tag for Member in Group


  • jonnycha
    Participant

    @jonnycha

    Hi BP community,

    I’m trying to find a conditional tag that checks whether the current user is a member of a specific group.

    My intention is to use in conjunction with Menu Item Visibility Control plugin to conditionally display a menu item depending on whether a user is member of a particular group or not.

    This is my first post here, so apologies if I’m in the wrong place.

    Many thanks for your help.

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

  • shanebp
    Moderator

    @shanebp

    To get the group ids for a member, use groups_get_user_groups.
    To get all the info about each group that a member belongs to, use bp_get_user_groups.
    Both functions are in buddypress\bp-groups\bp-groups-functions.php


    jonnycha
    Participant

    @jonnycha

    Thank you so much @shanebp.

    I’m using:

    in_array(4, groups_get_user_groups(get_current_user_id()))

    For the menu item visibility. It works perfectly with an admin user but not a normal member. Any idea why?


    shanebp
    Moderator

    @shanebp

    If the correct group ids are being returned by groups_get_user_groups, then it sounds like a permission issue in the Menu Item Visibility plugin.


    jonnycha
    Participant

    @jonnycha

    Thanks @shanepb, I’ll look into that

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar