Fix an error in SQL generation when `perm` is set and an array is passed for `post_status`. Adds unit test.
Props oso96_2000. Fixes #25523. git-svn-id: https://develop.svn.wordpress.org/trunk@27067 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d1cc542e1f
commit
b8e7bbb0f2
|
@ -2756,8 +2756,10 @@ class WP_Query {
|
|||
foreach ( $statuswheres as $index => $statuswhere )
|
||||
$statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))";
|
||||
}
|
||||
foreach ( $statuswheres as $statuswhere )
|
||||
$where .= " AND $statuswhere";
|
||||
$where_status = implode( ' OR ', $statuswheres );
|
||||
if ( ! empty( $where_status ) ) {
|
||||
$where .= " AND ($where_status)";
|
||||
}
|
||||
} elseif ( !$this->is_singular ) {
|
||||
$where .= " AND ($wpdb->posts.post_status = 'publish'";
|
||||
|
||||
|
|
|
@ -76,6 +76,5 @@ class Tests_Query extends WP_UnitTestCase {
|
|||
$first_query->reset_postdata();
|
||||
$this->assertEquals( get_the_ID(), $post_id );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -533,4 +533,14 @@ class Tests_Query_Results extends WP_UnitTestCase {
|
|||
$this->assertFalse( $this->q->is_month );
|
||||
$this->assertFalse( $this->q->is_year );
|
||||
}
|
||||
|
||||
function test_perm_with_status_array() {
|
||||
global $wpdb;
|
||||
$this->q->query( array( 'perm' => 'readable', 'post_status' => array( 'publish', 'private' ) ) );
|
||||
$this->assertTrue( $this->q->have_posts() );
|
||||
$this->assertContains( "(({$wpdb->posts}.post_status = 'publish') OR ({$wpdb->posts}.post_author = 0 AND ({$wpdb->posts}.post_status = 'private')))",
|
||||
$this->q->request
|
||||
);
|
||||
$this->assertNotContains( "({$wpdb->posts}.post_status = 'publish') AND", $this->q->request );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue