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 ) { ?>

1 Answer 1

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);
1
  • I ended up using shuffle which worked perfectly! Commented Jul 8, 2013 at 21:29

Your Answer

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

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