我正在编写一个简单的脚本来显示按rand和post_date排序的帖子。我在下面尝试了这个,但是它不起作用:
$myposts = get_posts('numberposts=4&orderby=rand post_date&order=ASC);
你的代码可以工作,但是在rand
之后添加post_date
是毫无用处的…
SQL查询看起来像这样:
SELECT [...] ORDER BY RAND() ASC, post_date ASC
RAND()
将返回浮点值,它不太可能返回两次相同的值,因此按post_date (rand之后)排序是无用的。
Try
$myposts = get_posts('numberposts=4&orderby=post_date,rand&order=ASC);