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


    kfdr44
    Participant

    @kfdr44

    Is this good idea to use the tag to find the relevant post and ideas? I want to try for my blog.


    kennynewbie
    Participant

    @kennynewbie

    From there, you’ll need to write an outline and flesh out your essay, which should consist of an introduction, body, and conclusion.
    After your essay is drafted, spend some time revising it to ensure your writing is as strong as possible.
    Don’t worry is professional research paper writing service

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