Make WordPress Core

Ticket #19198: 19198.4.diff

File 19198.4.diff, 1.6 KB (added by wonderboymusic, 13 years ago)
  • tests/phpunit/tests/query/results.php

     
    369369                        'child-two',
    370370                ), wp_list_pluck( $posts, 'post_title' ) );
    371371        }
     372
     373        function test_exlude_from_search_empty() {
     374                global $wp_post_types;
     375                foreach ( array_keys( $wp_post_types ) as $slug )
     376                        $wp_post_types[$slug]->exclude_from_search = true;
     377
     378                $posts = $this->q->query( array( 'post_type' => 'any' ) );
     379
     380                $this->assertEmpty( $posts );
     381                $this->assertRegExp( '#AND 1=0#', $this->q->request );
     382
     383                foreach ( array_keys( $wp_post_types ) as $slug )
     384                        $wp_post_types[$slug]->exclude_from_search = false;
     385
     386                $posts2 = $this->q->query( array( 'post_type' => 'any' ) );
     387
     388                $this->assertNotEmpty( $posts2 );
     389                $this->assertNotRegExp( '#AND 1=0#', $this->q->request );
     390        }
    372391}
  • src/wp-includes/query.php

     
    24552455
    24562456                if ( 'any' == $post_type ) {
    24572457                        $in_search_post_types = get_post_types( array('exclude_from_search' => false) );
    2458                         if ( ! empty( $in_search_post_types ) )
     2458                        if ( empty( $in_search_post_types ) )
     2459                                $where .= ' AND 1=0 ';
     2460                        else   
    24592461                                $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')";
    24602462                } elseif ( !empty( $post_type ) && is_array( $post_type ) ) {
    24612463                        $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $post_type) . "')";