WordPress.org

Make WordPress Core

Changeset 28622


Ignore:
Timestamp:
05/29/2014 08:41:53 PM (8 years ago)
Author:
wonderboymusic
Message:

If post_status is passed to WP_Query as an array containing 'any' and anything else, don't exclude the other values if they match when running any's exclusion logic.

Adds unit tests.

Fixes #28007.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r28613 r28622  
    27682768            $p_status = array();
    27692769            $e_status = array();
    2770             if ( in_array('any', $q_status) ) {
    2771                 foreach ( get_post_stati( array('exclude_from_search' => true) ) as $status )
    2772                     $e_status[] = "$wpdb->posts.post_status <> '$status'";
     2770            if ( in_array( 'any', $q_status ) ) {
     2771                foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) {
     2772                    if ( ! in_array( $status, $q_status ) ) {
     2773                        $e_status[] = "$wpdb->posts.post_status <> '$status'";
     2774                    }
     2775                }
    27732776            } else {
    27742777                foreach ( get_post_stati() as $status ) {
  • trunk/tests/phpunit/tests/post/query.php

    r28621 r28622  
    742742        $this->assertEqualSets( $ordered, wp_list_pluck( $attached->posts, 'ID' ) );
    743743    }
     744
     745    function test_post_status() {
     746        $statuses1 = get_post_stati();
     747        $this->assertContains( 'auto-draft', $statuses1 );
     748
     749        $statuses2 = get_post_stati( array( 'exclude_from_search' => true ) );
     750        $this->assertContains( 'auto-draft', $statuses2 );
     751
     752        $statuses3 = get_post_stati( array( 'exclude_from_search' => false ) );
     753        $this->assertNotContains( 'auto-draft', $statuses3 );
     754
     755        $q1 = new WP_Query( array( 'post_status' => 'any' ) );
     756        $this->assertContains( "post_status <> 'auto-draft'", $q1->request );
     757
     758        $q2 = new WP_Query( array( 'post_status' => 'any, auto-draft' ) );
     759        $this->assertNotContains( "post_status <> 'auto-draft'", $q2->request );
     760
     761        $q3 = new WP_Query( array( 'post_status' => array( 'any', 'auto-draft' ) ) );
     762        $this->assertNotContains( "post_status <> 'auto-draft'", $q3->request );
     763    }
    744764}
Note: See TracChangeset for help on using the changeset viewer.