I want to show activity loop for certain groups only.

If I use

<?php if ( bp_has_activities( array(bp_ajax_querystring( 'activity' ),'object' => 'groups','per_page'=>6 ,'primary_id' => $group_id, 'page' => isset($_REQUEST['page']) ? $_REQUEST['page'] : 1 ) ) ) : ?>

I can pass one group ID to filter results.

The problem is that I have an array of groups IDs. I tried

<?php if ( bp_has_activities( array(bp_ajax_querystring( 'activity' ),'object' => 'groups','per_page'=>6 ,'in' => $groups_ids, 'page' => isset($_REQUEST['page']) ? $_REQUEST['page'] : 1 ) ) ) : ?>

But 'in' => $array only takes an array of activities IDs. How to achieve this?

2 Answers 2


After getting all the groups_ids i get all activities_ids by doing:

    global $bp,$wpdb;
    $groups_ids = implode(', ', $groups_ids);
    $sql = "SELECT id FROM {$bp->activity->table_name} WHERE component = 'groups' AND item_id IN ({$groups_ids})";
    $activity_ids = $wpdb->get_results( $sql);
    $a_id = array();
    foreach ($activity_ids as $activity_id )
        $a_id[] = $activity_id->id;

Then i get only one activity loop with the specified groups by doing:

$params = array('per_page' => '6',  'in' => $a_id);

if ( bp_has_activities($params) )   :

You should state which version of BP you're using.

Try using:

function groups_get_groups( $args = '' ) 
in bp-groups\bp-groups-functions.php 


function bp_has_groups( $args = '' ) 
in bp-groups\bp-groups-template.php 

Note the include re group ids in both functions.

Then use a loop. while ( bp_groups() ) : bp_the_group();

In general, look at the bp-default theme files to see how things are called. In this case, looking at: bp-themes\bp-default\groups\groups-loop.php will makes things easier for you.

  • Im trying to retrieve activities, not groups. Im trying to get the activity loop for certain groups. Im using latest version by the way (WP and BP)
    – chifliiiii
    Apr 6, 2013 at 22:11
  • You should explicitly state the versions you are using. You're trying to get activities for certain groups, yes? Get the groups you want first. Then use an activity loop. Or you could write a custom query.
    – shanebp
    Apr 7, 2013 at 15:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.