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
This commit is contained in:
parent
4983a8b8d0
commit
05f0bcabec
@ -1293,7 +1293,7 @@ class WP_Adjacent_Post {
|
|||||||
$query_args = array(
|
$query_args = array(
|
||||||
'posts_per_page' => 1,
|
'posts_per_page' => 1,
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'post_type' => 'post',
|
'post_type' => $this->current_post->post_type,
|
||||||
'orderby' => 'date',
|
'orderby' => 'date',
|
||||||
'order' => 'previous' === $this->adjacent ? 'DESC' : 'ASC',
|
'order' => 'previous' === $this->adjacent ? 'DESC' : 'ASC',
|
||||||
'ignore_sticky_posts' => true,
|
'ignore_sticky_posts' => true,
|
||||||
|
@ -175,22 +175,35 @@ class Tests_Link extends WP_UnitTestCase {
|
|||||||
// Need some sample posts to test adjacency
|
// Need some sample posts to test adjacency
|
||||||
$post_one = $this->factory->post->create_and_get( array(
|
$post_one = $this->factory->post->create_and_get( array(
|
||||||
'post_title' => 'First',
|
'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_two = $this->factory->post->create_and_get( array(
|
||||||
'post_title' => 'Second',
|
'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_three = $this->factory->post->create_and_get( array(
|
||||||
'post_title' => 'Third',
|
'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_four = $this->factory->post->create_and_get( array(
|
||||||
'post_title' => 'Fourth',
|
'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
|
// 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->go_to( get_permalink( $post_one->ID ) );
|
||||||
$this->assertEquals( $post_three, get_adjacent_post( false, null, false ) );
|
$this->assertEquals( $post_three, get_adjacent_post( false, null, false ) );
|
||||||
remove_filter( 'get_next_post_sort', array( $this, 'filter_next_post_sort_limit' ) );
|
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 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user