pre_relevanssi_related | post_relevanssi_related

do_action( 'pre_relevanssi_related', int $post_id )
do_action( 'post_relevanssi_related', int $post_id )

These action hooks run before and after Relevanssi fires the Related Posts queries.

Parameters

$post_id
(int) The post ID for the post these related posts are related to. This parameter was introduced in version 2.26.0.

More information

Because Relevanssi uses the Relevanssi search engine to fetch the Related Posts, everything that applies to regular searching applies to the Related Posts searches. The Related Posts searches are different, though, and may require a different approach. Relevanssi provides these action hooks that you can use to modify the search settings. Hook an action to pre_relevanssi_related to modify the settings and undo the changes in post_relevanssi_related.

Relevanssi has some default functionality added to these hooks. In pre_relevanssi_related, Relevanssi introduces the following changes:

add_filter( 'relevanssi_ok_to_log', '__return_false' );
add_filter( 'pre_option_relevanssi_searchblogs', '__return_false' );
add_filter( 'pre_option_relevanssi_searchblogs_all', 'relevanssi_return_off' );

These filters disable the logging and make sure Relevanssi only does the searches within the single site (multisite searching in Related Posts would be a problem). In post_relevanssi_related, Relevanssi removes these filters.