Make WordPress Core

Opened 5 years ago

Last modified 4 years ago

#49294 new defect (bug)

If multiple posts has same date, get_previous_post() and get_next_post() returns only first/last of them

Reported by: oskarijarvelin's profile oskarijarvelin Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

get_previous_post() and get_next_post() both uses get_adjacent_post() -function, which uses date for query. If query return multiple posts for same date, function only returns first or last post depending on $previous -parameter. As a result, if you have multiple posts for a same date, get_previous_post() and get_next_post() functions does not work as meant to.

Found one mention about this issue about a year earlier: https://wordpress.stackexchange.com/questions/330276/get-next-post-and-get-previous-post-return-wrong-posts

Change History (3)

#1 @joyously
5 years ago

I have seen this in the Theme Unit Test data, because several posts were artificially given the same date/time. It probably does not come up much in real life to have the exact same date/time on multiple posts. But it is still very confusing when it does happen.

#2 @SergeyBiryukov
5 years ago

  • Component changed from General to Posts, Post Types

#3 @talldanwp
4 years ago

Potentially a duplicate of #42936?

Note: See TracTickets for help on using tickets.