relevanssi_post_to_excerpt

apply_filters( 'relevanssi_post_to_excerpt', object $_post );

Filters the post object before an excerpt is created from it.

Parameters

$_post
(object) The post object. Always equivalent to WP_Post, but is not always specifically a WP_Post object.

More information

When Relevanssi creates an excerpt from a post in relevanssi_do_excerpt(), the first step is to filter the post object with this filter hook. After that the search query is filtered and tokenized, the post content is filtered and processed and the excerpt generated.

This filter offers the first chance to manipulate the proceedings by changing the post object somehow. If you wish to modify the post content, it’s probably better to use relevanssi_pre_excerpt_content (which runs before the_content filters are applied) or relevanssi_excerpt_content (which runs after the_content filters). But if you for example use hand-built excerpts as source material for Relevanssi-generated excerpts, there’s no filter to modify them, so this filter comes in handy:

// Modifies excerpts so that all strawberries become raspberries.
add_filter( 'relevanssi_post_to_excerpt', 'rlv_modify_excerpt' );
function rlv_modify_excerpt( $_post ) {
  $_post->post_excerpt = str_replace( 'strawberry', 'raspberry', $_post->post_excerpt );
  return $_post;
}