Skip to content

Commit

Permalink
Merge pull request #2719 from 10up/fix/issue-2715
Browse files Browse the repository at this point in the history
Fix RelatedPosts::get_related_query() call
  • Loading branch information
felipeelia committed Apr 25, 2022
2 parents d0edece + 0d7ba57 commit d32612f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/classes/Feature/RelatedPosts/RelatedPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions tests/php/features/TestRelatedPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down

0 comments on commit d32612f

Please sign in to comment.