Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_has_groups() Help


  • techguy
    Participant

    @crashutah

    I’m trying to make a little more sense of the documentation on the Groups loop: http://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-groups-loop/

    First, in the code it has bp_has_groups() but then the documentation says bp_has_site_groups() Can you use either of them or is that a mistake in the documentation?

    Also, could someone give me an example of the way to add a few parameters to the bp_has_site_groups() to filter by say type=random and max=3 and user_id=2 Does it need to have an array passed in or something?

    Thanks. Once I learn I’ll update the documentation too.

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

  • Boone Gorges
    Keymaster

    @boonebgorges

    Yikes! bp_has_site_groups() was deprecated a couple versions ago. Use bp_has_groups().

    Two ways to pass arguments:
    1) bp_has_groups( 'type=random&max=3&user_id=' . $user_id ) (just to give you a sense of how you might put a variable in there

    2) $args = array(
    'type' => 'random',
    'max' => 3,
    'user_id' => $user_id
    );
    if ( bp_has_groups ( $args ) ) { ...

    The second method is a bit easier to handle when you’re passing in a large number of arguments.


    r-a-y
    Keymaster

    @r-a-y

    Updated the codex to bp_has_groups().


    techguy
    Participant

    @crashutah

    Thanks @boonebgorges

    There’s no option that will get all the groups that ‘user_id’ => $user_id is not a member of right? I could certainly get all groups and check if the person is a member, but that’s not very efficient.


    Boone Gorges
    Keymaster

    @boonebgorges

    To the best of my knowledge there is nothing that does that. You could try extending the database class with a new query along those lines, though.


    techguy
    Participant

    @crashutah

    Ok, I added the sample code that Boone offered to the codex as well. Probably not needed if you’re good at PHP, but very beneficial if you’re a hack job like me.

    I’ll have to look at extending the database class. Then, I assume I’d have to add the code for a new parameter for bp_has_groups as well. Might be a good way to dip my toes into contributing to the core. Although, first I think I need to dip into the core for the required lower case.

    Thanks for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘bp_has_groups() Help’ is closed to new replies.
Skip to toolbar