From 0f82bf684c7138a429e000c8282f42308c5385d3 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 12 Oct 2022 12:42:30 -0300 Subject: [PATCH 1/2] Pass an array to comment_post_type --- includes/classes/Indexable/Comment/Comment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/classes/Indexable/Comment/Comment.php b/includes/classes/Indexable/Comment/Comment.php index 090177f787..c2ccbf498e 100644 --- a/includes/classes/Indexable/Comment/Comment.php +++ b/includes/classes/Indexable/Comment/Comment.php @@ -443,8 +443,8 @@ public function format_args( $query_vars ) { */ if ( ! empty( $query_vars['post_type'] ) ) { $filter['bool']['must'][]['bool']['must'] = [ - 'term' => [ - 'comment_post_type.raw' => $query_vars['post_type'], + 'terms' => [ + 'comment_post_type.raw' => array_values( (array) $query_vars['post_type'] ), ], ]; From 2ee6a526ecd32f992dde7d86b667825ec3f1cf14 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 12 Oct 2022 12:49:01 -0300 Subject: [PATCH 2/2] Comments: Test array of post types --- tests/php/indexables/TestComment.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/php/indexables/TestComment.php b/tests/php/indexables/TestComment.php index 6c837d7300..d20d096394 100644 --- a/tests/php/indexables/TestComment.php +++ b/tests/php/indexables/TestComment.php @@ -1527,6 +1527,22 @@ public function testCommentQueryPostType() { } $this->assertEquals( 2, count( $comments ) ); + + + $comments_query = new \WP_Comment_Query( [ + 'ep_integrate' => true, + 'post_type' => [ 'post', 'page' ], + ] ); + + $this->assertTrue( $comments_query->elasticsearch_success ); + + $comments = $comments_query->get_comments(); + + foreach ( $comments as $comment ) { + $this->assertTrue( in_array( $comment->comment_post_ID, [ $post_id_1, $post_id_2, $post_id_3 ] ) ); + } + + $this->assertEquals( 4, count( $comments ) ); } /**