Free version of Relevanssi doesn’t show ACF fields
-
I understand the Premium version of Relevanssi has support for ACF fields built in but I have the free version. I’m working on a way to grab the information from the database and then spit it out on the search results page. This is what I have come up with so far:
/************** FUNCTIONS.PHP ****************/ // Relevanssi does not show ACF fields - this is a work-around for specific fields in the DB function excerpt_function($content, $post, $query) { global $wpdb; // Grab everything in the ACF content fields from the DB and spit it out in the search result excerpt. If new ACF modules/fields are added in the future then they need to have their 'modules_#_name_name_content' and so on added to show up in the Relevanssi search. $fields = $wpdb->get_col("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta WHERE meta_key LIKE '%_content' AND NOT '_modules%'"); 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; } add_filter('relevanssi_excerpt_content', 'excerpt_function', 10, 3);
This part of the db query is working great:
$fields = $wpdb->get_col("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta WHERE meta_key LIKE '%_content'
I’m getting content from ACF fields in my search results pages – but:
AND NOT '_modules%'");
isn’t stopping content. The meta_value of these fields is like ‘field_############’ nonsense I don’t want in my search results. I’m working on understanding how SQL AND, OR and NOT Operators work together.
- This topic was modified 5 years, 7 months ago by .
- This topic was modified 5 years, 7 months ago by . Reason: Fixing formatting
The page I need help with: [log in to see the link]
- The topic ‘Free version of Relevanssi doesn’t show ACF fields’ is closed to new replies.