Make WordPress Core


Ignore:
Timestamp:
06/30/2021 04:59:10 AM (4 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/invalidQueries.php

    r49902 r51276  
    100100
    101101    /**
     102     * Test WP Query with an invalid post type in a mutiple post type query.
     103     *
     104     * @ticket 48556
     105     */
     106    public function test_unregistered_post_type_wp_query_multiple_post_types() {
     107        global $wpdb;
     108
     109        $query = new WP_Query(
     110            array(
     111                'post_type' => array( 'unregistered_cpt', 'page' ),
     112            )
     113        );
     114        $posts = $query->get_posts();
     115
     116        $this->assertContains( "{$wpdb->posts}.post_type = 'unregistered_cpt'", self::$last_posts_request );
     117        $this->assertCount( 1, $posts, 'the valid `page` post type should still return one post' );
     118    }
     119
     120    /**
    102121     * Test WP Query with an invalid post type specified in the URL.
    103122     *
Note: See TracChangeset for help on using the changeset viewer.