WordPress.org

Make WordPress Core

Ticket #32651: patch.diff

File patch.diff, 1.5 KB (added by willybahuaud, 6 years ago)

This patch include posts with same datetime in the query, exclude the current post, and do a second order by ID

  • trunk/wp-includes/link-template.php

     
    15711571        }
    15721572
    15731573        $adjacent = $previous ? 'previous' : 'next';
    1574         $op = $previous ? '<' : '>';
     1574        $op = $previous ? '<=' : '>=';
    15751575        $order = $previous ? 'DESC' : 'ASC';
    15761576
    15771577        /**
     
    16001600         * @param bool   $in_same_term   Whether post should be in a same taxonomy term.
    16011601         * @param array  $excluded_terms Array of excluded term IDs.
    16021602         */
    1603         $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms );
     1603        $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.ID != %d AND p.post_type = %s $where", $current_post_date, $post->ID, $post->post_type ), $in_same_term, $excluded_terms );
    16041604
    16051605        /**
    16061606         * Filter the ORDER BY clause in the SQL for an adjacent post query.
     
    16121612         *
    16131613         * @param string $order_by The `ORDER BY` clause in the SQL.
    16141614         */
    1615         $sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
     1615        $sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order, p.ID $order LIMIT 1" );
    16161616
    16171617        $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
    16181618        $query_key = 'adjacent_post_' . md5( $query );