Hi,
I would like to create custom excerpts for the search function.
I use this code and this works for these fields:
function custom_fields_to_excerpts($content, $post, $query) {
$fields = get_field('inhoud', $post->ID);
if($fields){
foreach($fields as $field){
if ($field['acf_fc_layout'] == "2_kolommen_tekst_afbeelding-3_1-3"){
$content .= " " . $field['kolom1'];
} elseif ($field['acf_fc_layout'] == "2_kolommen_afbeelding_tekst"){
$content .= " " . $field['kolom2'];
}
}
}
return $content;
}
add_filter('relevanssi_excerpt_content', 'custom_fields_to_excerpts', 10, 3);
I also have some repeater fields and I can’t get these to be included in the excerpt.
The repeater fields are structured as follows:
‘inhoud’ (flexibele content) > ‘2_kolommen_repeater_container’ > ‘2_kolommen_repeater’ (repeater field) > ‘kolom1’ / ‘kolom2’
So the last ones (‘kolom1’ and ‘kolom2’) are the fields with the actual content and need to be included in the excerpt.
I tried some things with the suggestions mentioned here: https://support.advancedcustomfields.com/forums/topic/acf-and-relevanssi/
Like this:
if($fields){
foreach($fields as $field){
$content .= " " . $field['2_kolommen_repeater_container'];
}
}
This doesn’t work. I guess it has something to do with the repeater field itself doesn’t containing text. It needs to check a subfield of the repeater.
Does anyone have a suggestion to get this working?