Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robgolbeck/9aa6f42581edbabcdc77 to your computer and use it in GitHub Desktop.
Save robgolbeck/9aa6f42581edbabcdc77 to your computer and use it in GitHub Desktop.
Enable Relvanssi search plugin to index custom fields
<?php
// Use this if you need the Relevanssi advanced search plugin to index content in custom fields.
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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment