Created
May 14, 2015 23:57
-
-
Save robgolbeck/9aa6f42581edbabcdc77 to your computer and use it in GitHub Desktop.
Enable Relvanssi search plugin to index custom fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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