BP 11: Fetch Activities for or Excluding a Group of Users

Coming soon in 11.0, we’ve made it possible to fetch activity items for a specific group of users, or to fetch activity items excluding a group of users. The new parameters are user_id__in and user_id__not_in, following a familiar WordPress naming convention.

<?php 
// A couple of users are so cool I would like to do something
// featuring just their updates 
$activity_args = array(
	'user_id__in' => array( 3, 7 ),
);

$activity_items = bp_activity_get( $activity_args );

foreach ( $activity_items as $activity ) {
	// Do soemthing interesting with these activities...
}
?>

Or to find activities, excluding updates from users with the ID 3 and 7, simply use the other new option.

<?php 
// I'd like to block updates from a couple of annoying users. 😮
$activity_args = array(
	'user_id__not_in' => array( 3, 7 ),
);

$activity_items = bp_activity_get( $activity_args );

foreach ( $activity_items as $activity ) {
	// Do soemthing interesting with these activities...
}
?>

This change is simple but powerful! For instance, you could create custom interest activity streams, or build a mute feature to let your members take a break from other, too-chatty users!. 🙂