Sidebar random author spotlight

You can cut a lot of steps out of this if you use get_users() instead of your custom SQL query. You can then select a random user out of that array using array_rand() (native PHP function, not a wordpress function) and it will return the key you should be using. Here’s an example:

$users = get_users( $your_params );
$id = array_rand( $users, 1 );

$user = $users[$id];

This will leave you with $user, which will contain a user object with just about everything you could want on a user…or at least the ability to obtain what you need. get_avatar() will do the thumbnail…assuming you want the default.

Leave a Comment

tech