WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 3 months 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 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
12 months 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
12 months ago

  • Component changed from General to Posts, Post Types

#3 @talldanwp
3 months ago

Potentially a duplicate of #42936?

Note: See TracTickets for help on using tickets.