Pages

Monday, November 26, 2012

How to count exact number of users when BuddyPress does it wrong

There have been instances where BuddyPress function does not count active members. It is possible because they use different tables for counting. If you want to count exact members of your wordpress site then you can by-pass buddypress function. I have written a few lines of code which you can use in your functions.php file.

///count users in wp_users table and display at various places
function my_bp_core_get_active_member_count(){
 global $wpdb;
$user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");
return $user_count;
}
add_filter( 'bp_core_get_active_member_count', 'my_bp_core_get_active_member_count');

What this code does is, whenever bp_core_get_active_member_count() function is triggered it routes to my custom function mentioned above and returns the users count which will be displayed across the entire site. Got it? No? then write to me!

2 comments:

  1. HI there,

    Thanks this worked to get the counter correct, however its not actually adding the users to the members page?

    Thanks
    Willem

    ReplyDelete
  2. This problem derailed me for days, but your post fixed the count! Finally, thank you!

    ReplyDelete