I am using the premium version that our vendor set up. A developer wrote the code before I was hired, so I am not entirely sure how it all works. The code used is below. I hope this helps a little more. All I know is that the excerpt that is showing for search results contains content from old page versions.
add_filter('relevanssi_excerpt_content', 'excerpt_function', 10, 3);
function excerpt_function($content, $post, $query) {
global $wpdb; $fields = $wpdb->get_col("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta");
// ignore these fields
$ignore = array('_edit_lock', '_edit_last', '_wp_page_template');
foreach($fields as $key => $field){
if(!in_array($field, $ignore)){
$field_value = get_post_meta($post->ID, $field, TRUE);
if(!ctype_digit($field_value)) $content .= ' ' . ( is_array($field_value) ? implode(' ', $field_value) : $field_value );
}
}
// Remove random terms from showing in the search. These are related to the names of the ACF field names
$wordlist = array('acf_id_1', 'acf_id_2', 'acf_id_3', 'acf_id_4');
foreach ($wordlist as &$word) {
$word = '/\b' . preg_quote($word, '/') . '\b/';
}
$wordlist = array('/field_\w*/', '/\w*_callout/', '/\w*_content/', '/banner_image/', '/banner_image_with_overlay/', '/small_gray_tile_links/', '/large_gray_tile_blocks/', '/gray_tile_blocks/', '/profile_blocks/', '/block_links/', '/three_columns_and_image/', '/leadership_profiles/', '/gray_tile_blocks/', '/vertical_slider/', '/tile_layout/',
'/two_columns_70-30/', '/two_columns_50-50/', '/two_columns_with_small_accordions/', '/content_with_2_column_text/', '/page_header/', '/content_header/', '/content content_subheader/', '/content small_accordions/', '/content sidebar/', '/content accordions/',
'/content two_columns accordions/', '/\[download_tools\]/', '/\[related_info\]/', '/two_columns/', '/sidebar/', '/content/', '/\#bb0000/', '/notify/', '/onehr_category/');
$content = preg_replace($wordlist, '', $content);
// The excerpt ready with bits removed from it
return $content;
}
and it is being called on search.php with
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
<div class="content-article search-entry clearfix">
<a class="content-article-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<div class="content-article-text"><?php the_excerpt(); ?></div>
</div>
<?php
}
}
else {
?>
<div class="search-no-results"><p>No results were found.</p></div>
<?php
}
?>