diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php index 7064d1690f..9f6aaa5327 100644 --- a/src/wp-includes/class-wp-comment-query.php +++ b/src/wp-includes/class-wp-comment-query.php @@ -758,7 +758,7 @@ class WP_Comment_Query { foreach ( $post_fields as $field_name => $field_value ) { // $field_value may be an array. $esses = array_fill( 0, count( (array) $field_value ), '%s' ); - $this->sql_clauses['where']['post_fields'] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value ); + $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value ); } } diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php index 34037bda7c..eda13a973c 100644 --- a/tests/phpunit/tests/comment/query.php +++ b/tests/phpunit/tests/comment/query.php @@ -534,6 +534,43 @@ class Tests_Comment_Query extends WP_UnitTestCase { $this->assertEqualSets( array( $c1, $c2 ), $found ); } + /** + * @ticket 35478 + */ + public function test_multiple_post_fields_should_all_be_respected() { + $posts = array(); + + $posts[] = self::factory()->post->create( array( + 'post_status' => 'publish', + 'post_author' => 3, + ) ); + + $posts[] = self::factory()->post->create( array( + 'post_status' => 'draft', + 'post_author' => 4, + ) ); + + $posts[] = self::factory()->post->create( array( + 'post_status' => 'draft', + 'post_author' => 3, + ) ); + + $comments = array(); + foreach ( $posts as $post ) { + $comments[] = self::factory()->comment->create( array( + 'comment_post_ID' => $post, + ) ); + } + + $q = new WP_Comment_Query( array( + 'post_status' => 'draft', + 'post_author' => 3, + 'fields' => 'ids', + ) ); + + $this->assertSame( array( $comments[2] ), $q->comments ); + } + function test_get_comments_for_post() { $limit = 5;