0

I'm trying to randomly display my users and I was wondering if I could edit the answer on this page to suit my needs (multiple users instead of a single user): Sidebar random author spotlight

Here's my code (I can easily switch to WP_user_query if need be)

<?php
    $args = array(
        'fields' => 'all_with_meta',
        'exclude' => array(1),
    );
    $users = get_users( $args );
foreach( $users as $user ) { ?>
3

I don't see an "orderby Rand()" parameter for either get_users or WP_User_Query. There is a filter called pre_user_query that could be used but I am not sure I see the benefit of that when shuffle will randomize the array you already have.

$args = array(
    'fields' => 'all_with_meta',
    'exclude' => array(1),
);
$users = get_users( $args );
shuffle($users);
var_dump($users);
| improve this answer | |
  • I ended up using shuffle which worked perfectly! – Austin Biggs Jul 8 '13 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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