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?
- What is This esc_html_e() i wordpress php?
- Create a global variable for use in all templates
- How to order WP_User_Query results to match the order of an array of user IDs?
- How to auto login user again after change user_login
- Display only text to WordPress loop without loosing the text formatting
- How to change post count in wordpress loop?
- How can I loop into two different DIVS without repeating the DIVs
- How to track a users progress through pages by inserting data into WordPress Database?
- How do I know what variables are passed in a filter/action and what their meaning is?
- WordPress loop specific thumbnail size
- get understrap pagination to work with custom query
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- Way to display “Yesterday”, “Today”
- How can i display post loop in table format?
- multiple if statements [closed]
- have_posts() execution failure
- How does the ternary operator work in the wordpress loop post?
- Cannot display or echo alt text on featured image
- Using Advanced Custom Fields to create a per page slider
- WordPress Search Results for Multiple Post Types
- User’s total comment count excluding comments on their own posts
- Using loop pagination on single.php
- User management system similar to wordpress one?
- Get value from shortcode to do something
- Add New User, extra fields which are required?
- Modify user profile data through scripting?
- How to set variable, pass it to a partial file and remove it after?
- Do not execute If User is login as Administrator or any Specific Role
- Display category name only once inside loop
- Can’t find infinite loop cause
- Best practice for show data to one specific user?
- Changing the_posts_navigation() html output
- get_users meta_query: REGEXP not working for matching new lines
- WP_Query fails despite having 1 post
- “operation successful” message
- wp_query get the 2nd post
- Loop stopped working
- How to loop through all the attached images in a post, and get their url one by one
- Store post content in a php variable and output them using for loop
- How to add div blocks after certain set of post
- php if username is role
- How do I remove a category from a wordpress loop>
- Show recent posts starting at a specific number archive
- How to get the last category name of a child category?
- WordPress query undefined offset in loop
- Is it possible to create new user from external form using REST API?
- Foreach loop inside an array_merge
- Issue with custom loop in Archive page
- Show current user posts only
- get_users(); Is an Undefined Function When Used in Cron Job
- WordPress loop by meta key that is an array? and how loop multiple arrays
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- home.php show blog posts as grid view
- show something only when user comes from specific page at remote host?
- Show site content based on user role
- WordPress call post-ID in jquery
- How to extract information from a wp_query result?
- Echo array value
- List all anchor links on a page
- How to break up php code to avoid echo
- WordPress get last inserted user id
- Woocommerce display orders with products from specific categories to specific admins
- Products listing check if meta checkbox is checked
- update_user_meta as multiple value but with same meta key
- Call WP Rest-Api to GET /users/me returned NOTHING in console
- Responsive loop with 3 columns inside row then 2 columns
- If user has clicked link add class and store using PHP/WordPress
- Use WP user status (logged_in) to manage access to independent application
- How do if all posts has this category ID then do this
- Query to show average # of months all accounts with specific role have been active
- ERR_TOO_MANY_REDIRECTS / To Force SSL Logins and SSL Admin Access
- Date of last blog update for specific authors only?
- View tag description on page
- PHP for loop not working as intended
- Editable Student file associated with basic User ID
- Insert div after every three posts in home.php [duplicate]
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Updating custom user meta
- Display product attributes for current product
- For each 3 posts, show a different post type
- Using page template to fetch posts in page
- Create Customization Controls from Array
- Get author meta of all writers
- ACF loop and php formatting
- How to have post count after each listed category
- How can I put a custom field as the link of a button shortcode?
- Let users register weight each day and save it in DB
- Transient Loop Not working as expected
- Custom Meta Box If Else Statement
- Conditional in foreach loop is outputting content twice
- Alternative loop syntax error [closed]
- is there away to hide php code in wordpress not to show in PAGES
- Import users and custom user meta from csv
- rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
- Getting invalid user ID error when creating a new user with wp_insert_user
- How do I exclude the current post from the upcoming post query