diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php
index e30094d..9c8c80b 100644
--- a/src/wp-includes/class-wp-comment-query.php
+++ b/src/wp-includes/class-wp-comment-query.php
@@ -634,6 +634,8 @@ class WP_Comment_Query {
 		$post_id = absint( $this->query_vars['post_id'] );
 		if ( ! empty( $post_id ) ) {
 			$this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id );
+		} else {
+			$this->sql_clauses['where']['post_id'] = 'comment_post_ID IN ( 0, "")';
 		}
 
 		// Parse comment IDs for an IN clause.
diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php
index 5d250ea..4bd6f7c 100644
--- a/tests/phpunit/tests/comment/query.php
+++ b/tests/phpunit/tests/comment/query.php
@@ -39,7 +39,16 @@ class Tests_Comment_Query extends WP_UnitTestCase {
 			'fields' => 'ids',
 		) );
 
-		$this->assertEqualSets( array( $c1 ), $found );
+		$this->assertEmpty( $found );
+		$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
+		$c3 = self::factory()->comment->create( array( 'comment_post_ID' => '', 'comment_approved' => '1' ) );
+
+		$q = new WP_Comment_Query();
+		$found = $q->query( array(
+			'post_id' => 0,
+			'fields' => 'ids',
+		) );
+		$this->assertEqualSets( array( $c2, $c3 ), $found );
 	}
 
 	/**
