Last active
November 8, 2022 19:34
-
-
Save siteoptimo/9049115 to your computer and use it in GitHub Desktop.
This will allow to order a wordpress user query by random.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// put this in your functions.php | |
add_filter('pre_user_query', function(&$query) { | |
if($query->query_vars["orderby"] == 'rand') { | |
$query->query_orderby = 'ORDER by RAND()'; | |
} | |
}); | |
// Query will look like this: | |
$args = array('orderby' => 'rand', 'number' => 5); | |
$users = WP_User_Query($args); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Guys, Thanks