I found a realy great solition here. !!
It is a function that kindof ‘adds’ 'orderby' => 'rand'
as a parameter.
What it does it that when someone uses that parameter, the function will query the database using regular MySQL, where random is always possible 🙂
The function:
// 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()';
}
});
The loop will be something like:
// Query will look like this:
$args = array('orderby' => 'rand', 'number' => 5);
$users = WP_User_Query($args);
Related Posts:
- What is the most efficient way to search users by their display name?
- Get users that likes the post
- How to get URL of current page displayed?
- Getting only direct child pages in WordPress with get_pages
- Query multiple custom post types in single loop
- What is This esc_html_e() i wordpress php?
- How can I fetch loop of post titles via AJAX?
- Inject post (from specific category) between posts in Loop
- Knowing the total number of posts before to get into the loop
- How to search display_name column when using WP_User_Query
- Create a global variable for use in all templates
- Add extra field to users
- How to order WP_User_Query results to match the order of an array of user IDs?
- get product attributes for current product and store it in a variable
- Integrating WordPress to my website, while keeping my own authentication system
- Display user’s total comment count outside The Loop
- Build a content and excerpt grid loop with paging and options for # of posts
- Changing user_nicename
- How to auto login user again after change user_login
- Can i check if user is doing any ajax request?
- Displaying post per day
- How do I create a WP user outside of WordPress and auto login?
- Network installation giving errors when viewing or adding a user
- Installing wp3.2.1 on IIS; getting empty sessions
- Guidance with The Loop for CMS
- Showing user ID on user main page from screen options
- Display only text to WordPress loop without loosing the text formatting
- Getting the Current User
- How to loop over custom fields in a page template?
- How to add active class to custom menu using while loop and wp_list_pages
- Want to separate sections of posts. Can you restart loop?
- How do I hide specific user profile fields?
- MySQL query performed 4 times inside loop
- Print html when custom field has value inside while loop
- Alter secondary loop to exclude posts from current page category
- Post from one loop in different containers?
- How to get user by display_name with WP_User_Query
- Custom Loop Pagination on WordPress
- Specific Loop For 2 Within Each
- Authenticating to WordPress, using my own authentication two-factor system
- delete an array element when its date expires
- Two posts in same div – WP loop
- Infinite-Scroll Plugin and Jetpack Infinite Scroll Plugin – Adding to “Thoughts” Theme
- How to change post count in wordpress loop?
- How can I loop into two different DIVS without repeating the DIVs
- User Defined order on get_categories?
- How to track a users progress through pages by inserting data into WordPress Database?
- How to get a list of all users registered before a given date?
- Woocommerce, recognize the loop of related products
- How do I know what variables are passed in a filter/action and what their meaning is?
- Store loop into array
- Looping through WP_Post Object
- WordPress loop specific thumbnail size
- get understrap pagination to work with custom query
- WP_User_Query order by meta_key that is an array
- automated tests as a user?
- How can I default to all WordPress roles when parameter is not included in shortcode?
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
- Easiest way to show total number of subpages
- Delete option value from array using update_option()
- Custom Loop through category menu to include sub categories
- When would you use $_post instead of $post?
- Output 2 items within the Loop
- How do I display the function the_content in this loop?
- get_users(…) only returns one user
- Show Custom Taxonomy Title
- How to exclude specific category from the get_the_category(); array
- Way to display “Yesterday”, “Today”
- How can i display post loop in table format?
- List User order by ID in Descending order (Backend)
- spliting posts into two columns
- Returning a value from a PHP page
- Must Use Plugin Causing Query Error
- How to get to a specific position in wp_query?
- Advanced Custom Fields: Post Object – Not returning data [closed]
- How to speed up a wordpress function with multiple loops?
- Facebook “like” open graph meta in header.php
- Custom excerpt function re-factoring
- How can I show the post thumbnail from the most recent of a certain post type, in widget?
- Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
- multiple if statements [closed]
- How to select WooCommerce products by post_meta and order them
- How can I add pagination and how can I change thumbnail size?
- Get all user meta by meta key instead of ID
- How to Display a Single Post Excerpt
- have_posts() execution failure
- How does the ternary operator work in the wordpress loop post?
- $wpdb->flush(); breaks the loop
- How to get a list of all possible values of a specific user meta key?
- Use object in template part
- Get first URL from post content
- How can I add multiple ‘tax_query’ arrays via a loop?
- ACF page while loop breaks footer while loop
- Using foreach loop breaks
- Cannot display or echo alt text on featured image
- Using Advanced Custom Fields to create a per page slider
- Split loop into two columns, how to favor one side over the other
- WordPress Search Results for Multiple Post Types