WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

closed as off-topic by kaiser Aug 1 '14 at 23:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 1 down vote accepted

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) )   :
share|improve this answer
Take a look at codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column It will return an array for you so you don't need the foreach. – shanebp Apr 11 '13 at 22:26
really helpful, it works for me – StreetCoder Apr 22 '14 at 6:52

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.

share|improve this answer
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 '13 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 '13 at 15:01

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