Display Random Author with Details in Sidebar

Your best option is to get a random post author which is a user ID so here is a function to do just that:

function get_random_author_wpa91320(){
    global $wpdb;
    $id = $wpdb->get_var("
        SELECT post_author
        FROM $wpdb->posts
        WHERE post_type="post"
        AND post_status="publish"
        ORDER BY RAND()
        LIMIT 1
        ");
    return $id;
}

And once you have that function in your theme’s functions.php file you can replace this line:

<?php $users = get_users(); $id = array_rand( $users, 1 ); $user = $users[$id]; ?>

with

<?php $user = get_user_by('id', get_random_author_wpa91320() ); ?>

Update

here is a modified version to get all users from the database who have at least on post and use PHP rand to return a random id

function get_random_author_wpa91320_2(){
    global $wpdb;
    //this will get all users with posts
    $ids = $wpdb->get_col("
        SELECT DISTINCT post_author
        FROM $wpdb->posts
        WHERE post_type="post"
        AND post_status="publish"
        "
    );
    return $ids[rand(0,count($ids) -1)];
}

This way is like you count every user once and not based on the post number he has.

Leave a Comment