admin管理员组文章数量:1430143
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";**
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";**
Share
Improve this question
edited May 25, 2019 at 12:20
LoicTheAztec
3,39117 silver badges24 bronze badges
asked May 24, 2019 at 21:25
RahmanRahman
213 bronze badges
1
|
1 Answer
Reset to default 2You can use ORDER BY rand()
, but it's a very heavy query as a temporary table is created for it.
A WC_Product_Query
or a WP_Query
could be a good alternative to WPDB
custom query. Both support 'orderby' => 'rand',
…
本文标签: woocommerce offtopicHow to Order by random on a SQL query
版权声明:本文标题:woocommerce offtopic - How to Order by random on a SQL query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745465520a2659517.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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 – Tom J Nowell ♦ Commented May 24, 2019 at 22:07