Home › Forums › General Issues › Making customfields searchable? › Reply To: Making customfields searchable?
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 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.