From 05f0bcabecd091b24dcb51e5fd9493de88901bff Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 24 Mar 2014 21:29:14 +0000 Subject: [PATCH] Use the current post's post type when determining post adjacency. props ethitter. fixes #26937. git-svn-id: https://develop.svn.wordpress.org/trunk@27692 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/link-template.php | 2 +- tests/phpunit/tests/link.php | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index d58c951810..16e5f6472e 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -1293,7 +1293,7 @@ class WP_Adjacent_Post { $query_args = array( 'posts_per_page' => 1, 'post_status' => 'publish', - 'post_type' => 'post', + 'post_type' => $this->current_post->post_type, 'orderby' => 'date', 'order' => 'previous' === $this->adjacent ? 'DESC' : 'ASC', 'ignore_sticky_posts' => true, diff --git a/tests/phpunit/tests/link.php b/tests/phpunit/tests/link.php index 96b60f0c8b..dc1ee06051 100644 --- a/tests/phpunit/tests/link.php +++ b/tests/phpunit/tests/link.php @@ -175,22 +175,35 @@ class Tests_Link extends WP_UnitTestCase { // Need some sample posts to test adjacency $post_one = $this->factory->post->create_and_get( array( 'post_title' => 'First', - 'post_date' => '2012-01-01 12:00:00' + 'post_date' => '2012-01-01 12:00:00', ) ); $post_two = $this->factory->post->create_and_get( array( 'post_title' => 'Second', - 'post_date' => '2012-02-01 12:00:00' + 'post_date' => '2012-02-01 12:00:00', ) ); $post_three = $this->factory->post->create_and_get( array( 'post_title' => 'Third', - 'post_date' => '2012-03-01 12:00:00' + 'post_date' => '2012-03-01 12:00:00', ) ); $post_four = $this->factory->post->create_and_get( array( 'post_title' => 'Fourth', - 'post_date' => '2012-04-01 12:00:00' + 'post_date' => '2012-04-01 12:00:00', + ) ); + + // Use pages to test post-type adjacency + $page_one = $this->factory->post->create_and_get( array( + 'post_title' => 'First Page', + 'post_date' => '2013-01-01 12:00:00', + 'post_type' => 'page', + ) ); + + $page_two = $this->factory->post->create_and_get( array( + 'post_title' => 'Second Page', + 'post_date' => '2013-02-01 12:00:00', + 'post_type' => 'page', ) ); // Add some meta so we can join the postmeta table and query @@ -233,6 +246,13 @@ class Tests_Link extends WP_UnitTestCase { $this->go_to( get_permalink( $post_one->ID ) ); $this->assertEquals( $post_three, get_adjacent_post( false, null, false ) ); remove_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort_limit' ) ); + + // Test post-type specificity + $this->go_to( get_permalink( $page_one ) ); + $this->assertEquals( $page_two, get_adjacent_post( false, null, false ) ); + + $this->go_to( get_permalink( $page_two ) ); + $this->assertEquals( $page_one, get_adjacent_post( false, null, true ) ); } /**