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:
1 2 | 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:
1 2 | 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:
1 2 3 | 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.