relevanssi_related_posts_cache_id

apply_filters( 'relevanssi_related_posts_cache_id', string $cache_id )

Filters the name of the transient field that caches the Related posts for each post.

Parameters

$cache_id
(string) The cache identifier, default 'relevanssi_related_posts_' . $post_id . '_jo'.

More information

When Relevanssi generates the related posts for each post, the results are stored in a cache. Generating the posts is an expensive task that cannot be done every time the page is viewed. The related posts in Relevanssi are designed so that each post has one set of related posts, so there’s just one cache per post.

If you want to change that, to for example have two separate sets of related posts for each post, you can use this filter hook to change the name of the cache transient for one set so that you can have two sets cached.

For example, you could first print out one set of related posts using the default settings and the default cache. Then set a global flag parameter, add a filter on pre_option_relevanssi_related_settings to modify the related posts settings and then use this:

add_filter( 'relevanssi_related_posts_cache_id', 'rlv_second_related_cache' );
function rlv_second_related_cache( $cache_id ) {
  global $second_related_posts;
  if ( $second_related_posts ) {
    $cache_id = str_replace( '_jo', '_2nd', $cache_id );
  }
  return $cache_id;
}

This would change the cache id to relevanssi_related_posts_1_2nd if the $second_related_posts flag is on.