Jeremie Ges
Jeremie Ges

Reputation: 2745

Sort query by rand and post_date wordpress

I'm cooking a simple script to display posts order by rand and post_date. I tried this below but it's doesn't work :

$myposts = get_posts('numberposts=4&orderby=rand post_date&order=ASC);

Thank's in advance !

Upvotes: 1

Views: 643

Answers (2)

soju
soju

Reputation: 25312

Your code works, but adding post_date after rand is simply useless...

SQL query will look like this :

SELECT [...] ORDER BY RAND() ASC, post_date ASC

RAND() will return float value, it will unlikely return twice the same value, so ordering by post_date (after rand) is useless.

Upvotes: 1

Barif
Barif

Reputation: 1552

Try

$myposts = get_posts('numberposts=4&orderby=post_date,rand&order=ASC);

Upvotes: 0

Related Questions