[wp-trac] [WordPress Trac] #12650: Multiple posts with same date do not link to each other with next_post_link and previous_post_link.

WordPress Trac wp-trac at lists.automattic.com
Sat Mar 20 00:55:33 UTC 2010


#12650: Multiple posts with same date do not link to each other with next_post_link
and previous_post_link.
--------------------------+-------------------------------------------------
 Reporter:  bfrohs        |       Owner:  bfrohs                            
     Type:  defect (bug)  |      Status:  new                               
 Priority:  high          |   Milestone:  Unassigned                        
Component:  General       |     Version:  2.9.2                             
 Severity:  normal        |    Keywords:  next_post_link, previous_post_link
--------------------------+-------------------------------------------------
 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).

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12650>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list