Query: Check each post-type's capabilities when querying multiple post-types.

When querying multiple post types, check the `read_private_posts` capability for each post type when determining which post statuses to return. This ensures private posts appear in search results and archives for users permitted to read them.

Props leogermani, hellofromTonya, jeffpaul, peterwilsoncc.
Fixes #48556.



git-svn-id: https://develop.svn.wordpress.org/trunk@51276 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2021-06-30 04:59:10 +00:00
parent 41c00084dc
commit 212c928038
3 changed files with 240 additions and 61 deletions

View File

@@ -98,6 +98,25 @@ class Tests_Query_InvalidQueries extends WP_UnitTestCase {
$this->assertCount( 0, $posts );
}
/**
* Test WP Query with an invalid post type in a mutiple post type query.
*
* @ticket 48556
*/
public function test_unregistered_post_type_wp_query_multiple_post_types() {
global $wpdb;
$query = new WP_Query(
array(
'post_type' => array( 'unregistered_cpt', 'page' ),
)
);
$posts = $query->get_posts();
$this->assertContains( "{$wpdb->posts}.post_type = 'unregistered_cpt'", self::$last_posts_request );
$this->assertCount( 1, $posts, 'the valid `page` post type should still return one post' );
}
/**
* Test WP Query with an invalid post type specified in the URL.
*