Codex Home → Developer Resources → Activity Stream and date_query
Activity Stream and date_query
If you have a lot of activity entries on your site, load times can suffer dramatically when viewing activity streams.
You can use the date_query argument to speed things up by limiting the entries to only those from the past day or week or month, etc.
But you cannot add it as a string in the usual fashion. For example, adding a per_page argument:
Instead, you need to use an array, which is easy enough until you try to include the value of bp_ajax_querystring( 『activity』 ) as an argument and the 『Load More』 button stops working properly.
Here』s the solution. You can paste it in your overload of the activity-loop template or you could use the bp_before_has_activities_parse_args filter.
$date_limit,
),
);
$activity_args['per_page'] = 5;
?>
// etc.
Note the use of wp_parse_str to add the query string needed for the 『Load More』 button.
And you can use conditionals to change the date_query argument depending on which activity stream you』re viewing:
?12345678910111213if ( bp_is_activity_directory() ) { $date_limit = date("Y-m-d H:i:s", strtotime("-1 week")); } elseif( bp_is_group() ) { $date_limit = date("Y-m-d H:i:s", strtotime("-1 month")); } else { // profile stream $date_limit = date("Y-m-d H:i:s", strtotime("-1 year")); }