@graemebryson5,
you need a function to fetch the activity_comment
type in bp_activity
table. For the count itself, we use mysql count. Here it goes:
function bpfr_get_activities_comment_count() {
global $wpdb;
$user_id = bp_displayed_user_id();
if ( bp_is_active( 'activity' ) ) {
// DB query
$total = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$wpdb->prefix}bp_activity WHERE user_id = '%d' AND type = 'activity_comment'", $user_id ) );
return $total;
}
}
Now you can echo bpfr_get_activities_comment_count
wherever you need it on your profile template.
Here an example to get it on profile header.
function bpfr_total_comments() {
echo 'My comments: '. bpfr_get_activities_comment_count();
}
add_filter( 'bp_before_member_header_meta', 'bpfr_total_comments' );
If you need more member activities counts, try Buddy Member Stats !
Absolutely perfect. Thanks for this Dan, I’ve been struggling with it for a few days now so it’s massively appreciated.
De nada. You’re welcome ! 🙂
@graemebryson5
8 years, 6 months ago
Hi,
I’m attempting to pull in a user’s activity_comment count into a bar on their profile alongside a post count and favourite count using the following snippet:
I’m implementing it with:
<?php echo get_user_comment_count( bp_displayed_user_id() ) ?>
On testing, this seems to cause an error as the page fails to load beyond the point of implementation. Could anyone help point me in the right direction to get it up and running?