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 5 replies - 1 through 5 (of 5 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


    Nick
    Participant

    @nickchomey

    @shanebp

    Not sure if I should create a new topic for this, but I’m curious as to which function I should be using – bp_get_user_groups or groups_get_user_groups. All I need are the IDs, but groups_get_user_groups doesn’t use wp_cache, and thus runs many redundant sql queries – this makes it seem like a completely redundant function. Or am I wrong?

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