Starting from WordPress version 4.5, you can use RAND(seed)
with the orderby
parameter.
However, when the value is simply RAND
(i.e. the uppercase of rand
), WP_Query
ignores it and defaults to the default sorting (which is by the post date).
I’ve confirmed that by inspecting the $query->request
:
-
With
'orderby' => 'RAND'
, theORDER BY
clause isORDER BY wp_posts.post_date DESC
. -
With
'orderby' => 'rand'
, theORDER BY
clause isORDER BY RAND()
.
So the solution is simple: Always use rand
, unless you want to use a seed.
Related Posts:
- WP_query taxonomy + get all posts with two terms from same taxonomy
- SQL Statement generated by WP_Query not producing expected results
- Custom archive page based on array of categories and tags
- tax_query shows no results if nothing is selected
- get complex results set according to category structure
- Get image of latest post from taxonomies/categories
- Query Custom Post Type Order By Taxonomy Field
- Taxonomy search/filter with multiple taxonomies and multiple taxonomy terms
- Combining categories (Query posts with multiple taxonomy terms)
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- Automatically Query Parent Taxonomy
- Query most popular terms by taxonomy over 2 week period
- Custom taxonomy.php not working
- get all posts associated with a custom taxonomy
- Tax_Query using WP_Query not working
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- wp_query with meta_query and tax_query
- list all post who have mutual taxonomy as current taxonomy!
- Why pagination is not working with tax_query param?
- Taxonomy archive, categorised by other taxonomy, not hiding empty taxonomies
- Combine Tax Archive and Meta_Query in WP_Query
- Taxonomy Terms That Don’t Exist Display Results
- In Product Category archives how to show Posts having same/similar prod_cat slug structure?
- Object of class WP_Query could not be converted to int inside shortcode
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- List posts of terms but exclude one term
- WP_Query on “property” in the options table
- Query posts filter not working
- Output ACF field dynamicaly within a taxonomy loop [closed]
- Incorrect taxonomy ID assigned to post with custom query
- How to get an array of post data from wp_query result?
- How to only display posts whose meta_value field is not empty?
- How to print the excuted sql right after its execution
- How to add taxonomy filter on the query fly?
- Pagination returns 404 after page 20
- Make a WP Query search match exactly the search term
- post_type is ignored by WP_Query when ‘tag’ argument is included
- How to query posts of standard post format. For real
- Orderby menu_order doesn’t work
- WP_Query by Category Name
- Warning: urlencode() expects parameter 1 to be string, array given
- WP_Query OR clause for tax_query and keywords
- All sticky posts are returned in custom query
- query posts in functions.php and update a field
- get_posts() seemingly ignoring post_type
- If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?
- Can not switch the queried post in pre_get_posts hook
- Why use JSON API to display recent posts?
- Why query_vars get altered in WP_Query Object?
- Two different conditions with a single WP_Query
- Creating query to show which editor (classic or block) was last used to edit a post/page
- Tax query clause inside a meta query clause?
- Getting the current post number / make posts increment
- Optional Meta Query
- Set conditional on template based on referring page slug
- Multiple If Else with WP Query in WordPress
- Serve specific “template” page at any URL that ends in its slug
- WordPress search posts by author name with autocomplete
- WordPress pagination not working using WP_Query
- Meta_query on same meta key, with diffrenct values
- Can we return all category (not post) with Custom Query Filter? [closed]
- WP_Query – Exclude Posts
- Exclude Category filter from Portfolio section
- Get latest post revision with wp-query
- date_query seems to be ignored by wp_query
- Query Vars Not Set in Main Query
- Filter Custom Taxonomy Posts
- Config.php issue in WordPress
- Is it possible to query from external database? [duplicate]
- WP_Query freezing
- WP_Query to output chosen term and posts with no term assigned
- Need to add onclick javascript at backend of my wordpress site
- How do you determine if a result in a search query is a post or a page?
- WP_Query by keyword OR post tag
- Order WP_Query results by meta key value in custom query
- Display recent posts on another site
- WP_Query for products always returns empty
- Issue with data array format
- Meta Box WP_Query array for showing items with a certain relationship
- Multi-layered WP_Query
- `offset` WP_Query argument dont work via `pre_get_posts`
- Function the_posts_pagination() not compatible with WP_Query arguments
- Pagination of custom page with custom fields query
- WP_Query custom post with by general tags
- WP_Query() not filtering posts for category
- WP_User_Query Orderby Not Working
- WordPress post_status and meta_query
- How to pass a php variable to js within a template?
- Custom query: post__in parameter causes query to be empty
- Custom query return
- WP_Query: Meta_Query with serialized value (or a workaround)
- Query All Attachments and Order by Parent Publish Date
- WP_Query using meta_query with LIKE doesn’t return what it should
- Query post Pagination Problem
- How to organize a WP_Query’s list of posts by category and display category title?
- Pull Instagram images into an existing loop?
- Query_vars not working for me
- Filtering product search results using tags
- new WP_Query with order args – no more distinction between categories
- How to make OR condition in WP_Query