diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 96148ba20e..d53ec42788 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -3193,7 +3193,7 @@ class WP_Query { $cgroupby = "$wpdb->comments.comment_id"; } else { // Other non singular e.g. front $cjoin = "JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )"; - $cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'"; + $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' && post_type = 'attachment' ) ) AND comment_approved = '1'"; $cgroupby = ''; } diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index fd228910bb..a1f3665486 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -57,6 +57,13 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $this->assertQueryTrue('is_feed', 'is_single', 'is_singular', 'is_comment_feed'); } + function test_attachment_comments_feed() { + $attachment_id = self::factory()->post->create( array( 'post_type' => 'attachment' ) ); + self::factory()->comment->create_post_comments( $attachment_id, 2 ); + $this->go_to( get_post_comments_feed_link( $attachment_id ) ); + $this->assertQueryTrue( 'is_feed', 'is_attachment', 'is_single', 'is_singular', 'is_comment_feed' ); + } + function test_page() { $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) ); $this->go_to( get_permalink( $page_id ) ); diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index 30a32909c8..fa544319b1 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -703,4 +703,19 @@ class Tests_Query_Results extends WP_UnitTestCase { $result2 = $this->q->query( array( 'title' => 'Tacos', 'fields' => 'ids' ) ); $this->assertCount( 0, $result2 ); } + + /** + * @ticket 15610 + */ + public function test_main_comments_feed_includes_attachment_comments() { + $attachment_id = self::factory()->post->create( array( 'post_type' => 'attachment' ) ); + $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $attachment_id, 'comment_approved' => '1' ) ); + + $this->q->query( array( 'withcomments' => 1, 'feed' => 'feed' ) ); + + $this->assertTrue( $this->q->have_comments() ); + + $feed_comment = $this->q->next_comment(); + $this->assertEquals( $comment_id, $feed_comment->comment_ID ); + } }