Make WordPress Core

Opened 11 years ago

Last modified 6 years ago

#28026 new defect (bug)

previous_post_link returns incorrect post when posts have the same published date

Reported by: deplorableword's profile deplorableword Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.3
Component: Themes Keywords: has-patch needs-refresh
Focuses: template Cc:

Description

Version: 3.8.3

Overview: previous_post_link does not return the correct link when posts have exactly the same published date. Instead it, skips the post with the same published date and returns the next found post.

Steps to reproduce:

1) Publish a post. Post A
2) Using wp-admin create 2 draft posts. Draft B, Draft C
3) Switch to the post list view /wp-admin/edit.php
4) Switch to the link showing draft posts /wp-admin/edit.php?post_status=draft&post_type=post
5) Click the checkbox to select all draft posts, then in the Dropdown select Edit then Apply.
6) Change status dropdown to "Published" and then Update.
7) In single.php add a <?php previous_post_link() ?>
8) View Draft C, link should point to Draft B, instead it points to Post A.

Fix:

Quick look indicates that in link-template.php 1179 should be <= and >=

Attachments (4)

28026.patch (1.0 KB) - added by lpointet 11 years ago.
unittest.28026.diff (1.5 KB) - added by lektro 10 years ago.
Unit Test
refresh.28026.diff (1.0 KB) - added by lektro 10 years ago.
Refresh of initial patch
unittest-updated.28026.diff (1.2 KB) - added by lektro 10 years ago.
Updated unit test

Download all attachments as: .zip

Change History (11)

#1 @lpointet
11 years ago

Problem is, if you accept retrieving same date posts, they will show up for both
get_previous_post() and get_next_post() calls. So when you are on Draft C, you will see Draft B for both previous and next posts...
We could fix it by choosing whether Draft B is before or after Draft C, maybe thanks to their IDs?

I'll attach a patch with a reviewed 'WHERE' clause for get_adjacent_post() function.

@lpointet
11 years ago

#2 @deplorableword
11 years ago

  • Keywords has-patch added

Yeah, realise this has some complex cases, but as it was possible to cause the bug with the WordPress Admin figured it was worth reporting.

IDs make sense to me, I guess it's the only order we have which is unique?

#3 @SergeyBiryukov
11 years ago

  • Focuses template added; ui administration performance removed
  • Milestone changed from Awaiting Review to 4.0

This ticket was mentioned in IRC in #wordpress-dev by DrewAPicture. View the logs.


11 years ago

#5 @DrewAPicture
11 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from 4.0 to Future Release

No activity in 3 months, the patch needs to be refreshed, and this would need unit tests anyway. Punting.

#6 @DrewAPicture
11 years ago

  • Keywords needs-refresh added

@lektro
10 years ago

Unit Test

@lektro
10 years ago

Refresh of initial patch

@lektro
10 years ago

Updated unit test

#7 @chriscct7
9 years ago

  • Keywords needs-unit-tests removed
Note: See TracTickets for help on using tickets.