diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php index 2280487d09..c795e1216a 100644 --- a/src/wp-includes/author-template.php +++ b/src/wp-includes/author-template.php @@ -197,7 +197,7 @@ function get_the_author_posts() { if ( ! $post ) { return 0; } - return count_user_posts( $post->post_author ); + return count_user_posts( $post->post_author, $post->post_type ); } /** diff --git a/tests/phpunit/tests/user/author.php b/tests/phpunit/tests/user/author.php index 8646a9ba42..71fa99a37e 100644 --- a/tests/phpunit/tests/user/author.php +++ b/tests/phpunit/tests/user/author.php @@ -82,4 +82,21 @@ class Tests_User_Author extends WP_UnitTestCase { $GLOBALS['post'] = $this->post_id; $this->assertEquals( 1, get_the_author_posts() ); } + + /** + * @ticket 30904 + */ + function test_get_the_author_posts_with_custom_post_type() { + register_post_type( 'wptests_pt' ); + + $cpt_ids = $this->factory->post->create_many( 2, array( + 'post_author' => $this->author_id, + 'post_type' => 'wptests_pt', + ) ); + $GLOBALS['post'] = $cpt_ids[0]; + + $this->assertEquals( 2, get_the_author_posts() ); + + _unregister_post_type( 'wptests_pt' ); + } }