Adding custom fields stored in arrays to search results
-
I’m using Advanced Custom Fields to structure content in custom posts in WordPress. Relevanssi is working wonderfully for the most part by setting the “custom fields to index” field in the Relevanssi settings to “visible.” The problem, as described in the User Manual, is that “Relevanssi expects the custom field value to be a string, so if you’re storing serialized objects or arrays in your custom fields, indexing them might not work as expected.”
I’ve followed these instructions to add custom fields to the excerpt by first converting the array into a string, like so:
function custom_fields_to_excerpts($content, $post, $query) { /* * A custom function that returns an associative array of custom taxonomy names, e.g.: * array ( * [browsers] => array('chrome', 'safari'), * [providers] => array('google', 'yahoo'), * ) */ $app = my_get_app_filters($post->ID); // Convert associative array to string (ex: "chrome, safari, google, yahoo") $string = my_array_to_string($app['filters']); $content .= " " . $string; return $content; } add_filter('relevanssi_excerpt_content', 'custom_fields_to_excerpts', 10, 3);
No dice, though. Any idea how to give Relevanssi insight into custom fields stored in arrays?
- The topic ‘Adding custom fields stored in arrays to search results’ is closed to new replies.