$args=array(
'orderby' => 'rand',
'order' => 'DESC',
'posts_per_page' => 3,
'offset' => $offset,
);
$q = new WP_Query($args);
if($q->post_count>0){
$random_post = $q->posts[mt_rand(0,2)];
}
also, just a little note, ORDER BY RAND() is pretty bad for performance
Related Posts:
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Order by summing multiple values
- Debugging wp_query orderby for taxonomy
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- orderby in WP_query doesn’t works
- WP_Query with several meta_query-statements and order by meta_value
- WP_Query with “post_title LIKE ‘something%'”?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP_Query orderby date not working
- Order by DESC, ASC in custom WP_Query
- Secondary Sort (fallback) for WP_Query
- Query Posts in a Predefined Order
- Is it possible to wrap Geo Location search around WP_Query?
- Is it possible to select against a post’s parent’s fields with WP_Query?
- How do I order pages and categories by ID or name in the same query?
- WP_Query ordered by custom field that is a date string?
- How to make an activities stream mixing posts and comments?
- SQL Statement generated by WP_Query not producing expected results
- What is an efficient way to query based on post_meta?
- SQL query equivalent to WP User Query
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Order posts ascending with number in title
- how to retrieve specific product attribute value in an sql query?
- List taxonomy terms plus their latest post ordered by post date
- Order by the results of a function with WP_query
- WP_Query order by date in meta_value
- Advanced WP Query hogs the SQL server
- How to use order RAND() on WordPress?
- Show all parents and children in custom post type in right order
- Meta query with order by another custom field
- WordPress WP_Query orderby being overwritten
- Order Posts by meta value AND published date
- How can I pick a single post from the latest 3?
- Query post with meta_query where date is not in future
- WP User Query get all authors with last name starting with specific letter
- How do I sort posts with multiple pages
- How to correctly pass values to wpdb->prepare()?
- Order WP_Query by multiple fields, subtracting them from one another
- pre_get_posts order by not working
- How To Fix WP Query Returns Results But Shouldn’t?
- List of the years with posts presented
- Order By table field comment_status in WordPress > 4.0
- Slow WP_Query for custom post type
- Complex WP SQL Query
- WP_Query order result by date AND meta_value
- Order by title without taking into account ‘the’
- Sorting events by descending date, and ascending time if multiple events on a date
- WP_Query orderby author__in
- How to orderby multiple meta fields if some fields are empty
- Editing the default wordpress search
- Weird orderby => post__in issue
- How to extract specific post
- Changing sort order for presentation by Jetpack infinite scroll
- How to order posts by title after they have already been sorted by category
- meta_value_num not ordering all items
- wordpress ajax relationship query
- How to filter a query by multiple meta keys and order by other meta keys
- Multiple Orderby’s using random order WP_Query
- WP Query – order posts by meta field first and then order the rest
- Advanced WP_Query with meta_query, orderby?
- List of ways to access WordPress database?
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Order is breaking wp_query
- Query where ANDing slug values not working
- WP_Query: apply an SQL function to meta fileld value
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Filtering by multiple conditions in the loop
- Orderby two meta fields not working
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- how to retrieve WP_Query without ordering by date [duplicate]
- orderby ignored by wp_query
- WP_Query orderby
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- WP_Query() not working as expected
- How to sort store location by specific category order in WP store locations
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Custom order of posts in wp_query and different taxonomies
- WP_Query random ordering not working since 5.4
- What is the equivalent WP_Query of a SQL Query?
- WordPress Query custom ordering by temporary variable
- Order by meta date with a thousanth of a second defaults to post order
- How to get_comments() ordered by date and parent?
- WP Query. Ordering posts by another post types meta
- Best way to query posts and order by relevancy to query
- wp_query sorting – one specific meta_key value at last and then sort by create date
- query_posts based on a meta_key
- Display three sequential posts on each page load, without repeating previous
- What argument does my function need to echo get_results() query results
- Order posts by more than one variable (meta_key and publish date AND time)
- Create custom order sortby based on array of id
- Sort by meta key within same day
- Order Custom Field by Price
- Show sticky post before other WP_Query
- WP Query to order posts by multiple meta fields
- Order by multiple meta keys on wordpress
- How to return value from sql and display it
- wpdb LIKE request shows all database data
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- WP_Query sort by ACF date field (newest first) with blank dates first