relevanssi_excerpt_content showing fieldnames in search page results
-
Hi,
I’m trying to use the relevanssi_excerpt_content filter to show the content of my ACF custom fields in the search results page. The code I got from the comments of this post http://www.relevanssi.com/knowledge-base/relevanssi-excerpt-content/ works (the content of the ACF fields is showed) but strangely is also shows me the filename of the template the page is using (ex: xxx-xxx-page.php) and a series of numbers that I suppose refers to the fieldname stored in the database (ex: 1440978520:1 field_5474bdaad120a 831 default 63 field_5474bd336dc79).
This is my code:
‘
add_filter(‘relevanssi_excerpt_content’, ‘excerpt_function’, 10, 3);
function excerpt_function($content, $post, $query) {global $wpdb;
$fields = $wpdb->get_col(“SELECT DISTINCT(meta_key) FROM $wpdb->postmeta”);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;
}
‘I need this filter because I have many pages that have no text in the default content editor, only custom fields, and without it, the page search results shows nothing but the page title.
How can I hide those elements and show only the content of the ACF custom field?
I’m not that good in PHP so… any help appreciated.
Many thanks!
- The topic ‘relevanssi_excerpt_content showing fieldnames in search page results’ is closed to new replies.