2

I'm trying to display some statistics of my Wordpress site in the footer. One of these statistics is the amount of users that are signed up.

There is a function called count_users() to display these statistics as show in the Codex: count_users(). But this function seems very server intensive, especially since it will be called on every WordPress page.

I started looking for less server intensive alternative and found one called get_user_count() Codex: get_user_count(). Unfortunately, this only seems to work on Multisite installations.

Is it possible to enable this and other Multisite functions for regular installations??

3
  • 3
    have you considered using set_transient and get_transient to cache the result for however long you like so that you are not calling count_users on every pageload?
    – majick
    Apr 10, 2016 at 9:12
  • 1
    You should probably have a look at this answer Apr 10, 2016 at 14:08
  • added example :-)
    – majick
    Apr 12, 2016 at 13:27

1 Answer 1

1

get_transient / set_transient example:

function my_get_user_count() {
    $usercount = get_transient('usercount');
    if (!$usercount) {
        $usercount = count_users();
        set_transient('usercount',$usercount,600); // ten mins
    }
    return $usercount;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.