Display The Total Number Of Registered Users
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 );
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.