Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个简单的脚本来按 rand 和 post_date 显示帖子顺序。我在下面尝试了这个,但它不起作用:
$myposts = get_posts('numberposts=4&orderby=rand post_date&order=ASC);
提前致谢 !
您的代码有效,但添加post_date之后rand根本没用......
post_date
rand
SQL 查询将如下所示:
SELECT [...] ORDER BY RAND() ASC, post_date ASC
RAND()将返回浮点值,它不太可能返回两次相同的值,因此按 post_date (在 rand 之后)排序是没有用的。
RAND()
尝试
$myposts = get_posts('numberposts=4&orderby=post_date,rand&order=ASC);