You’ll need some custom sql. Put this in bp-custom.php
function contributor_count() {
global $wpdb;
$contributor_count = $wpdb->get_var( "SELECT COUNT(user_id) FROM {$wpdb->prefix}usermeta WHERE meta_key = '{$wpdb->prefix}capabilities' AND meta_value LIKE '%contributor%'" );
return $contributor_count;
}
Use it wherever you want like this:
echo contributor_count();
Sorry, I thought i replied to this!; much appreciated, thanks.
@dta_madrid
Further to @shanebp’s method, WordPress has a function called count_users()
which can be used to get the number of users in each role.
https://codex.wordpress.org/Function_Reference/count_users
$users = count_users();
// display total users (if you want to).
echo $users['total_users'] . ' total users';
// display count for contributors.
foreach( $users['avail_roles'] as $role => $count ) {
if ( $role == 'contributor' )
echo $count . ' contributors';
}
@henrywright
Much better approach – thanks.