5

I want to retrieve the modification date of the latest post. To do this, first I get the latest post:

$latest_post = get_posts()[0];

Can I be certain that the returned object is always the latest post or are there circumstances where the order of objects returned by get_posts() is different?

1 Answer 1

6

Yes and Maybe

Yes: According to https://developer.wordpress.org/reference/functions/get_posts/ the default is ordered by date in a descending order.

Maybe: But plugins may change the query through ie hook(s) pre_get_posts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.