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 );
Comments
5 responses to “Display The Total Number Of Registered Users”
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.
[…] Artikel habe ich bei wpengineer.com gefunden und woltle euch diesen nicht vorenthalten. Speicher diesen Artikel in deinen […]
[…] With the New Widget API Exclude a Category From “Turn Off Comments” Automatically. Display the Total Number of Registered Users RSS | […]