Home › Forums › General Issues › ACF and Relevanssi › Reply To: ACF and Relevanssi
Hi, I’ve just got some more grey hairs and got the code from the Relevassi blog post about this working so it will use custom fields in it’s excerpt. With this code and “custom search result snippets” turned on, it will highlight the search term.
Hope this helps others!!
add_filter('relevanssi_excerpt_content', 'custom_fields_to_excerpts', 10, 3);
function custom_fields_to_excerpts($content, $post, $query) {
$custom_field = get_post_meta($post->ID, 'normal_custom_field', true);
$content .= " " . $custom_field;
$custom_field = get_post_meta($post->ID, 'normal_custom_field2', true);
$content .= " " . $custom_field;
if($fields){
foreach($fields as $custom_field){
$content .= " " . $custom_field['repeater_sub_field_1'];
$content .= " " . $custom_field['repeater_sub_field_2'];
}
}
$fields = get_field('page_content', $post->ID);
if($fields){
foreach($fields as $custom_field){
if($custom_field['acf_fc_layout'] == 'layout_name_1'){
$content .= " " . $custom_field['sub_custom_field'];
$content .= " " . $custom_field['sub_custom_field2'];
} elseif ($custom_field['acf_fc_layout'] == 'layout_name_2'){
$content .= " " . $custom_field['sub_custom_field'];
}
}
}
return $content;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.