Display The Total Number Of Registered Users
December 9th, 2009 by Frank • WordPress Hacks • 5 Comments
Anyone who operates a community using WordPress, and would like to display the total number of registered users, can easily and quickly use the following small code snippet.
It reads via SQL the content of the table "users", and the numbers of IDs getting counted. This value simply gets wrapped around a text.
$myusers = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
echo sprintf( __('We have %s registered user.', 'myTextDomain') , $myusers );
Info
- Published in WordPress Hacks
- Tags: Advent Calendar, PHP, Theme, WordPress, WordPress Tutorials, WP
- Comment feed
- read: 13938 | today: 5
- leave a Comment


this is very usefull (at least for me :-)!
thank you...
but i try to implement this into a php sidebar widget
get_var("SELECT COUNT(ID) FROM $wpdb->users");
echo sprintf( __('We have %s registered user.', 'myTextDomain') , $myusers );
?>
and I get the following error :
Fatal error: Call to a member function on a non-object in --/versatile-k/wp-content/plugins/php-code-widget/execphp.php(37) : eval()'d code on line 2
hello,
so i have the same problem, the snippet doesnt work in the sidebar.maybe you can help?
thx
regards
Wahnfried
@wahnfried: Use
global $wpdb;
before query.