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??
1 Answer
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;
}