WordPress.org

Make WordPress Core

Ticket #32651: 32651.diff

File 32651.diff, 2.7 KB (added by wonderboymusic, 6 years ago)
  • src/wp-includes/link-template.php

     
    16361636        }
    16371637
    16381638        $adjacent = $previous ? 'previous' : 'next';
    1639         $op = $previous ? '<' : '>';
     1639        $date_compare = $previous ? '<=' : '>=';
     1640        $id_compare = '!=';
    16401641        $order = $previous ? 'DESC' : 'ASC';
    16411642
    16421643        /**
     
    16831684         * @param string $taxonomy       Taxonomy. Used to identify the term used when `$in_same_term` is true.
    16841685         * @param WP_Post $post           WP_Post object.
    16851686         */
    1686         $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, $taxonomy, $post );
    1687 
     1687        $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $date_compare %s AND p.ID $id_compare %d AND p.post_type = %s $where", $current_post_date, $post->ID, $post->post_type ), $in_same_term, $excluded_terms, $taxonomy, $post );
    16881688        /**
    16891689         * Filter the ORDER BY clause in the SQL for an adjacent post query.
    16901690         *
     
    16971697         * @param string $order_by The `ORDER BY` clause in the SQL.
    16981698         * @param WP_Post $post    WP_Post object.
    16991699         */
    1700         $sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post );
     1700        $sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order, p.ID $order LIMIT 1" );
    17011701
    17021702        $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
    17031703        $query_key = 'adjacent_post_' . md5( $query );
  • tests/phpunit/tests/link.php

     
    310310                $this->assertEquals( $p3, $found->ID );
    311311        }
    312312
     313        /**
     314         * @ticket 32651
     315         */
     316        function test_get_adjacent_post_same_date_time() {
     317                $one = $this->factory->post->create_and_get( array(
     318                        'post_date' => '2012-01-01 12:00:00',
     319                ) );
     320
     321                $two = $this->factory->post->create_and_get( array(
     322                        'post_date' => '2012-01-01 12:00:00',
     323                ) );
     324
     325                $three = $this->factory->post->create_and_get( array(
     326                        'post_date' => '2012-01-01 12:00:00',
     327                ) );
     328
     329                $this->go_to( get_permalink( $two ) );
     330
     331                $this->assertEquals( $three, get_adjacent_post( false, array(), false ) );
     332                $this->assertEquals( $one, get_adjacent_post( false, array(), true ) );
     333        }
     334
    313335        public function test_wp_make_link_relative_with_http_scheme() {
    314336                $link = 'http://example.com/this-is-a-test-http-url/';
    315337                $relative_link = wp_make_link_relative( $link );