How do I change the last line to order by rand? Now it's sorting by date of my woocommerce products.
INNER JOIN $wpdb->postmeta AS mt1 ON (posts.ID = mt1.post_id)
WHERE
posts.post_status = 'publish'
AND (mt1.meta_key = '_sale_price_dates_to' AND mt1.meta_value >= ".time().")
GROUP BY posts.ID
**ORDER BY posts.post_date DESC";**
WP_Query
. Also note that ordering things randomly in an SQL query is hideously expensive. It has to create a brand new table in memory with the same rows but randomly ordered before it can even begin searching