Related Posts API
ElasticPress understands data in real-time, so it can instantly deliver engaging and precise related content with no impact on site performance.
In addition to the Related Posts block, it is also possible to list related posts using ElasticPress API. Available functions are:
find_related
Get related posts for a given $post_id
. Use this in a theme or plugin to get related content.
PHP
$related_posts_array = \ElasticPress\Features::factory()
->get_registered_feature( 'related_posts' )
->find_related( $post_id, $return = 5 );
get_related_query
Get a WP_Query
object with the related posts for a given $post_id
.
PHP
$related_posts_query = \ElasticPress\Features::factory()
->get_registered_feature( 'related_posts' )
->get_related_query( $post_id, $return = 5 );