Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to query for groups

Viewing 17 replies - 1 through 17 (of 17 total)
  • @djpaul

    Keymaster

    In terms of the BuddyPress API or SQL or via a theme?

    @ajaxmac

    Participant

    I’d like to know more about querying groups through the BP API. I put together my own SQL query to get the last 5 activity updates from a group. I was unsure how to pass the required variables into which function to achieve this through a BP call.

    @boonebgorges

    Keymaster

    @ajaxmac – If you want to get group activity updates, you’ll want to query for *activities* rather than groups. Check out bp_has_activities() https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/. For example, you can get the last five activity updates from a group with a loop containing the following query:
    if ( bp_has_activities( 'max=5&object=groups&primary_id=' . $group_id ) ) (obviously you’ll have to get that $group_id from somewhere).

    Then use the rest of the activity loop to display the content. Check out buddypress/bp-themes/bp-default/activity/entry.php to see how bp-default displays a single activity item within the loop, and activity-loop.php to see an (albeit complicated) example of how bp-default initializes the loop with a query.

    @boonebgorges

    Keymaster

    By the way, similar loops exist for bp_has_groups(), bp_has_members(), etc. The codex is pretty good on these subjects: https://codex.buddypress.org/developer-docs/custom-buddypress-loops/

    @dlabbe

    Participant

    @boonebgorges I know this is a old thread, but it is exactly what I am looking for, but it is not working for me. I should say it is working, but I can’t get one parameter to work. I am using the bp_has_groups() to filter the groups loop and I need to only display certain groups either by id’s (which does not seem to be a option other the user_id) or by slug which will work, but it does not for what ever reason. I am building a search function that will search for groups within a radius of a zip code entered in by the user. My search code is not in play yet so that is not causing the issue…just trying to find a way to hook my search code into a query for the loops page and the slug option looks to be the only way unless I can use group_id’s somehow. This is how I used the slug as parameter.
    `$args = array(
    ‘slug’ => ‘group_slug’,
    ‘max’ => 3,
    ‘user_id’ => $user_id);
    if ( bp_has_groups ( $args ) ) { …’

    I looked in the data base for the slug name in the bp_groups table. Not sure if that is right, but it is not working. Like I said though…the other parameters seem to work.
    Thanks for any help you can give me.
    David

    @dlabbe

    Participant

    @boonebgorges sorry to bother you again…but do you have any ideas how this can be done or a direction to go in? thanks

    @boonebgorges

    Keymaster

    Try adding the following item to your $args array:
    `’type => ‘single-group’`

    @dlabbe

    Participant

    thanks that worked great for a single group to show with the slug $arg. Is there a way to pass more then one group into it. Meaning I want more then one group to be returned?

    @anonymized-96400

    Inactive

    A slug is unique within a certain scope, e.g. groups, blog posts or even usernames, so by definition you can’t get more than a single group returned when filtering by slug. As I told you before, you’ll have to wait for BP 1.3 (maybe 1.2.7? does someone know?) to be able to pass group ids into the loop.

    @boonebgorges

    Keymaster

    In BP 1.3, bp_has_groups() will takes an ‘include’ parameter. It’s already in the trunk.

    @dlabbe

    Participant

    thanks guys. As it stands I already have a custom page that I created that has a zip code search( by mile radius)….it loops and displays thru all the groups within that radius. I had to reconstruct the look and feel of the groups directory page into this custom search page. Works really well, but it would also be much better blended into the existing directory page…so at this time I guess I will have to wait till the new release comes.
    Any ideas when it will be released?

    @gerbilo

    Participant

    Another question for groups query experts.

    How to extract for example group name, permalink, status, description from group ID ?
    Something like bp_has_groups ( “group_id = ‘.$ID.’ “) ? Or maybe bp_get_group_name ( $ID) ?
    Cause this two functions doesn’t work for me..

    @anonymized-96400

    Inactive

    Something like this will work:
    `$group = new BP_Groups_Group( $group_id );

    echo $group->name;
    echo bp_get_group_permalink( $group );`

    @dlabbe

    Participant

    To extend on Travel-Junkie
    `$group = new BP_Groups_Group( $group_id );
    foreach ($group as $key => $value)
    {echo $key . ‘ = ‘ . $value. ‘‘;}`

    this will break down in list form all the information you need for the group.
    Here is another nice little trick that works hand in hand with information returned from the above script. Lets say you want to show an excerpt from the groups description .
    This passes the description in the bp_create_excerpt() function as well as set how many words you want returned…then echo out the results.
    `$description = $group -> description;
    $descibe_excerpt = bp_create_excerpt( $description, 20 );
    echo $descibe_excerpt;`

    @gerbilo

    Participant

    @Travel-Junkie, @DavidRLabbe – thank you very much guys for your support! It’s working like a charm, but i got one tiny question.. why it’s so hard to get group information based on group id? Cause for members we got several functions with pretty easy instructions :)

    @dlabbe

    Participant

    @gerbilo ….I agree…you would think group id would be the easiest to deal. From what I am guessing and hearing it might get easier as new version of BP surface. No complaints however…BP rocks in many ways as social webbing has taken over.

    @boonebgorges

    Keymaster

    We’re shooting for a late-January release of BP 1.3, so you don’t have long to wait.

    If you want to ensure that it gets out faster, check out a copy of the trunk and grab a ticket :) trac.buddypress.org

Viewing 17 replies - 1 through 17 (of 17 total)
  • The topic ‘How to query for groups’ is closed to new replies.
Skip to toolbar