include all custom fields in search excerpt
-
Relevanssi rocks.
I’m building a site that uses custom fields quite heavily via the Advanced Custom Fields plugin. In relevanssi settings I have set “Custom fields to index” to ‘all’. Now I want to show the custom fields content in my search result excerpts, and am following the instructions here:
https://www.relevanssi.com/knowledge-base/add-custom-fields-search-excerpts
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, 'custom_field_1', true); $content .= " " . $custom_field; $custom_field = get_post_meta($post->ID, 'custom_field_2', true); $content .= " " . $custom_field; return $content; }
However, this seems to require I enter each custom field name manually. My site uses so many custom fields that this would be very tedious. I’m also using many ACF Repeater fields and ACF Flexible Content fields which generate their own unique field names, so it’s not realistic to enter them all.
Is there a way to tweak the code above to display all custom field content in the search excerpts without having to enter them manually one by one?
Thanks in advance!
- The topic ‘include all custom fields in search excerpt’ is closed to new replies.