Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 0 down vote accepted

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

<?php
    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) )   :
endif;
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
add comment

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

Try using:

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

Or:

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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