diff --git a/includes/classes/Feature/RelatedPosts/RelatedPosts.php b/includes/classes/Feature/RelatedPosts/RelatedPosts.php index d59f32e77a..272de39551 100644 --- a/includes/classes/Feature/RelatedPosts/RelatedPosts.php +++ b/includes/classes/Feature/RelatedPosts/RelatedPosts.php @@ -148,7 +148,7 @@ public function get_related_query( $post_id, $return = 5 ) { * @return array|bool */ public function find_related( $post_id, $return = 5 ) { - $query = $this->get_related_query( $post_id, $return = 5 ); + $query = $this->get_related_query( $post_id, $return ); if ( ! $query->have_posts() ) { return false; diff --git a/tests/php/features/TestRelatedPosts.php b/tests/php/features/TestRelatedPosts.php index b84aa7c0de..6ca1acd9d9 100644 --- a/tests/php/features/TestRelatedPosts.php +++ b/tests/php/features/TestRelatedPosts.php @@ -90,6 +90,12 @@ public function testFindRelatedPostFilter() { $related = ElasticPress\Features::factory()->get_registered_feature( 'related_posts' )->find_related( $post_id ); $this->assertEquals( 2, count( $related ) ); $this->assertTrue( isset( $related[0] ) && isset( $related[0]->elasticsearch ) ); + + // Make sure it will use the number of posts to be returned. + $related = ElasticPress\Features::factory()->get_registered_feature( 'related_posts' )->find_related( $post_id, 1 ); + $this->assertEquals( 1, count( $related ) ); + $this->assertTrue( isset( $related[0] ) && isset( $related[0]->elasticsearch ) ); + remove_filter( 'ep_find_related_args', array( $this, 'find_related_posts_filter' ), 10, 1 ); }