I’ll post only the FUNCTIONS.PHP code:
// Relevanssi does not show ACF fields by default - this is a work-around for specific fields in the DB
function excerpt_function($content, $post, $query) {
global $wpdb;
// Grab everything in the ACF content fields from the DB and spit it out in the search result excerpt. If new ACF modules/fields are added in the future then they need to have their 'modules_#_name_name_content' and so on added to show up in the Relevanssi search.
$fields = $wpdb->get_col("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta WHERE meta_key LIKE '%_content' AND meta_key NOT LIKE '_modules%'");
foreach($fields as $key => $field){
$field_value = get_post_meta($post->ID, $field, TRUE);
$content .= ' ' . ( is_array($field_value) ? implode(' ', $field_value) : $field_value );
}
return $content;
}
add_filter('relevanssi_excerpt_content', 'excerpt_function', 10, 3);