diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 4b5aa1730c..2dcc95c949 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -2448,6 +2448,9 @@ class WP_Query { } elseif ( $q['post__in'] ) { $post__in = implode(',', array_map( 'absint', $q['post__in'] )); $where .= " AND {$wpdb->posts}.ID IN ($post__in)"; + } elseif ( isset( $this->query['post__in'] ) ) { + $post__in = 0; + $where .= " AND 1=0 "; } elseif ( $q['post__not_in'] ) { $post__not_in = implode(',', array_map( 'absint', $q['post__not_in'] )); $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; @@ -2458,6 +2461,9 @@ class WP_Query { } elseif ( $q['post_parent__in'] ) { $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) ); $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)"; + } elseif ( isset( $this->query['post_parent__in'] ) ) { + $post_parent__in = 0; + $where .= " AND 1=0 "; } elseif ( $q['post_parent__not_in'] ) { $post_parent__not_in = implode( ',', array_map( 'absint', $q['post_parent__not_in'] ) ); $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)"; diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index 20c45ba446..9c4ce065f9 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -402,6 +402,15 @@ class Tests_Query_Results extends WP_UnitTestCase { } + function test_empty_post__in() { + $posts1 = $this->q->query( array() ); + $this->assertNotEmpty( $posts1 ); + $posts2 = $this->q->query( array( 'post__in' => array() ) ); + $this->assertEmpty( $posts2 ); + $posts3 = $this->q->query( array( 'post_parent__in' => array() ) ); + $this->assertEmpty( $posts3 ); + } + function test_exlude_from_search_empty() { global $wp_post_types; foreach ( array_keys( $wp_post_types ) as $slug )