Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is it Possible to Get the Current Group ID While in the Loop? (Continued in New Post)

  • Does anyone know how to capture the current group id?

    `bp_get_group_id()` is empty upon inspection during the loop.

    Thanks.

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

  • modemlooper
    Moderator

    @modemlooper

    Thanks @modemlooper.

    My question is not how to display it. My question is how to capture it.

    Currently I assign it to a variable like this `$guid = bp_get_group_id();`

    The problem is that while I am in the loop of groups & discussions, the current group id is not being captured. `bp_get_group_id()` returns an empty string or NULL.

    Also, I issued a bug report on it as well.


    modemlooper
    Moderator

    @modemlooper

    `<?php
    global $bp;

    $guid = $bp->group->id;

    // do something with $guid
    ?>`

    @modemlooper

    Just tested your recommended code.

    `$guid` is still empty during the loop in my Groups.


    modemlooper
    Moderator

    @modemlooper

    what are you trying to do with variable?

    @modemlooper:

    `
    if (groups_is_user_mod( get_current_user_id(), $guid ) == “1”) return;
    elseif (groups_is_user_admin( get_current_user_id(), $guid ) == “1”) return;
    else …
    `

    Everything else works — `groups_is_user_mod()`, `groups_is_user_admin()`, and `get_current_user_id()`.

    Right now I have hardcoded the Group ID and assigned it to var $guid. But I want to do this dynamically so I don’t have to manually hardcode certain group ids.

    Here’s what I want to get to work:

    `
    if (groups_is_user_mod( get_current_user_id(), bp_get_group_id() ) == “1”) return;
    elseif (groups_is_user_admin( get_current_user_id(), bp_get_group_id() ) == “1”) return;
    `

    Thanks for helping !


    modemlooper
    Moderator

    @modemlooper

    did you try

    `bp_group_id()`

    In BP most get functions are wrapped if you looked at the function bp_group_id() it would echo the value of bp_get_group_id()

    @modemlooper,

    Tried `bp_group_id()` — no luck.


    modemlooper
    Moderator

    @modemlooper

    what about

    `if ( bp_group_is_mod() )

    if ( bp_group_is_admin() )`

    @modemlooper,

    I remember trying those last week and ended up having to resort to the if() statements I have included earlier in this thread.

    I have progressed to the point of having to hard code the group ID because I can’t capture it on the fly while in the Group section of the Loop.


    modemlooper
    Moderator

    @modemlooper

    You can get the group id but I think groups_is_user_mod will not work in the loop

    What are you trying to accomplish because if ( bp_group_is_admin() ) works for me

    If you are trying to show content based on group role then that would work

    @modemlooper (having technical trouble posting right now…stay tuned)

    @modemlooper (bp forum not letting me post nicely, so I am splitting my reply in 2 parts)

    @modemlooper,

    Out-of-the-box, BP has a Send Invites link on the Groups forum. We don’t want that link unless you are a Group Admin or Group Moderator. Currently, we only have 1 private group set at this time with a group moderator. It is Group 17. But I know we will be getting more and more of these instances and I want to avoid hard coding the Groups each time to control the Send Invites link.

    See my code below from a plug-in I wrote. It is in next thread post.

    @modemlooper,

    MAJOR FRUSTRATION — BP FORUM TELLS ME “It looks like you’ve already said that!”

    @modemlooper,

    let’s start a new thread. BP Is getting too deep in my shorts here.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Is it Possible to Get the Current Group ID While in the Loop? (Continued in New Post)’ is closed to new replies.
Skip to toolbar