[wp-trac] [WordPress Trac] #46929: posts with the same post_date does not

WordPress Trac noreply at wordpress.org
Mon Apr 15 10:55:40 UTC 2019

#46929: posts with the same post_date does not
 Reporter:  robertklodzinski  |      Owner:  (none)
     Type:  enhancement       |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  General           |    Version:  5.1.1
 Severity:  normal            |   Keywords:
  Focuses:                    |
 When a list of posts has exactly the same `post_date`, then the post order
 is broken. Moreover, the same post can be displayed on another page. The
 ordering also differs for different values of `posts_per_page`.

 Steps to reproduce (the issue can be seen also in wp-admin):
 1. create list of posts with the same `post_date`. You can manually change
 the date in the database. I stumbled upon this issue while cloning posts
 while using the [https://wordpress.org/plugins/duplicate-post/ Duplicate
 Post] plugin to duplicate posts for testing. It may be a good idea to have
 unique titles to visually see the problem.
 2. See the results
 3. Change the number of posts per page and verify them (do so for
 different number of posts per page)

 A workaround I used in my case was to order by `post_date` and
 additionally by `ID` (the higher `ID`, the newer DB record, so if a post
 has the same `post_date`, but higher `ID`, it should be also displayed
 higher on the list):

 function fix_post_order($query) {
   $query->set( 'orderby', [ 'date' => 'DESC', 'ID' => 'DESC' ] );
 add_action( 'pre_get_posts', 'fix_post_order' );

 Probably such case would not happen in pure WP without touching the DB
 (that's why I'm not creating a defect ticket), but I believe additional
 order by `ID` (apart from `post_date`) would be a good idea, anyway.

Ticket URL: <https://core.trac.wordpress.org/ticket/46929>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list