WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#12650 closed defect (bug) (duplicate)

Multiple posts with same date do not link to each other with next_post_link and previous_post_link.

Reported by: bfrohs Owned by: bfrohs
Milestone: Priority: normal
Severity: normal Version: 2.9.2
Component: General Keywords: needs-patch
Focuses: Cc:

Description

Example:

You have 4 posts with ID of 1, 2, 3, and 4.

post_dates are as follows:
1) 2010-03-19 08:42:01
2) 2010-03-19 08:42:02
3) 2010-03-19 08:42:02
4) 2010-03-19 08:42:04

Post 2 will link to post 1 with previous_post_link.
Post 2 will link to post 4 with next_post_link. - should be 3
Post 3 will link to post 1 with previous_post_link.
Post 3 will link to post 4 with next_post_link. - should be 2

This is due to not expecting two posts to have the same exact date (in a normal install, they probably wouldn't... but with multiple users, this becomes an issue). Currently, the code selects datetimes less than or greater than current time (does not include current time). It also only orders by post_date.

To fix this issue, you must change > and < to >= and <= to include the current time as well (all posts that were posted during that second). Then, to avoid linking to the same post, order by ID and add a WHERE clause to catch the post with an ID > or < (does not include current post... remains consistent in grabbing the prev/next post) than the current ID.

Fix attached.

Refer to lines 955, 956, 960, and 961 in attached file to see the fix.

Set priority to high because this is very important to sites with multiple users or to sites that import data from other systems and the datetime is flawed -- For example, the database I imported into Wordpress was imported into Drupal last year by another developer, but he did not transfer the timestamps to drupal. This caused our data to have 4+ rows per timestamp (imported all at once).

Attachments (2)

link-template.php (52.7 KB) - added by bfrohs 4 years ago.
has-patch
link-template.patch (1.3 KB) - added by layotte 4 years ago.
Patch created from previously attached PHP file…

Download all attachments as: .zip

Change History (10)

comment:1 bfrohs4 years ago

  • Milestone changed from Unassigned to 2.9.3
  • Status changed from new to accepted

bfrohs4 years ago

has-patch

comment:2 bfrohs4 years ago

  • Keywords has-patch added

comment:3 nacin4 years ago

  • Keywords needs-patch added; next_post_link previous_post_link has-patch removed
  • Milestone changed from 2.9.3 to 3.0
  • Priority changed from high to normal

Needs an actual patch. This is just a PHP file.

See http://core.trac.wordpress.org/#HowtoSubmitPatches.

comment:4 PeteMall4 years ago

  • Cc pete@… added

layotte4 years ago

Patch created from previously attached PHP file...

comment:5 layotte4 years ago

  • Keywords has-patch added; needs-patch removed

comment:6 nacin4 years ago

  • Milestone changed from 3.0 to 3.1

comment:7 nacin3 years ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Awaiting Triage to Future Release

You can't guarantee that IDs are going to be in order of the published date.

comment:8 nacin3 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from accepted to closed
Note: See TracTickets for help on using tickets.