How to display the number of users in a WordPress site
Recently at work I needed to display the number of users registered in a WordPress blog.
Searching the web gave me the following PHP and mySQL code to display the number of registered users:
<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
echo $users." registered users."; ?>
But we were using the Register Plus plugin with user moderation. Register Plus adds the prefix unverified__ to all unverified WordPress usernames (so they can’t log in). Needless to say, we wanted to not include these unverified users from the count – so I changed the code to this:
<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users WHERE user_login NOT LIKE 'unverified__%'");
echo $users." registered users."; ?>
Lastly, we wanted to not include the 3 WordPress administrators we have from the user count. So, I modified the code further like this:
<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users WHERE user_login NOT LIKE 'unverified__%'");
$admins = 3;
echo $users - $admins ." registered users."; ?&>
You can change the number in the line that says $admins = 3; to whatever number you want subtracted from the count.
And there you have it, an accurate WordPress registered user count.

October 27th, 2011 on 10:54 pm
I am looking to find out in which file(s) you place this code, and where. I have WordPress and am using the theme “Thirty Ten”, a child theme of Twenty Ten. Thanks!