WordPress.org

Make WordPress Core

Opened 3 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 (2)

#1 @joyously
3 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
3 months ago

  • Component changed from General to Posts, Post Types
Note: See TracTickets for help on using tickets.