Display The Total Number Of Registered Users

WordPress-Christmas-09Anyone 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 );

Posted

in

by

Comments

5 responses to “Display The Total Number Of Registered Users”

  1. Miss K Avatar

    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

  2. wahnfried Avatar
    wahnfried

    hello,
    so i have the same problem, the snippet doesnt work in the sidebar.maybe you can help?
    thx
    regards
    Wahnfried

  3. Michael Avatar

    @wahnfried: Use

    global $wpdb;

    before query.

  4. […] Artikel habe ich bei wpengineer.com gefunden und woltle euch diesen nicht vorenthalten. Speicher diesen Artikel in deinen […]

  5. […] With the New Widget API Exclude a Category From “Turn Off Comments” Automatically. Display the Total Number of Registered Users RSS | […]