Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: How do you show a member's total post count?


Boone Gorges
Keymaster

@boonebgorges

See if this does what you want. Put the following function in [your-theme]/functions.php or [plugin-dir]/bp-custom.php:

function get_activity_count_by_user( $user_id ) {
$args = array(
'per_page' => 10000,
'show_hidden' => true,
'user_id' => $user_id
);

if ( bp_has_activities( $args ) ) {
global $activities_template;
$count = $activities_template->total_activity_count;
} else {
$count = 0;
}

return $count;
}

Then call the function somewhere in a template, something like this:

<?php echo get_activity_count_by_user( $user_id ) ?>

making sure that $user_id is populated with the user_id of the person you are querying about.

You could filter this in various ways. To get just one kind of content, or content from just one component of the site, try some of the filters here: https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/. To exclude things (like anything having to do with blogs) is a bit tricker; after calling the $activities_template global, loop through each member of $activities_template->activities and check to see whether it’s the kind of thing you want. If not, reduce $activities_template->total_activity_count by one.

Skip to toolbar