Advertisement
Guest User

custom fields in relevanssi's search results

a guest
Jun 19th, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Render content for Relevanssi excerpt. This will load custom fields!
  4.  */
  5. add_filter('relevanssi_excerpt_content', 'my_relevanssi_excerpt_content');
  6. function my_relevanssi_excerpt_content($content, $post = '', $query = ''){
  7.   //Uncomment the following line if the custom fields belong to a single post-type. Increases performance!
  8.   //if ( $post->post_type != 'my_post-type' ) return $content;
  9.  
  10.   //Fill in your custom field names here:
  11.   $fields = array('myfield1', 'myfield1');
  12.   foreach($fields as $field){
  13.     //pay attention to $single (http://codex.wordpress.org/Function_Reference/get_post_meta)
  14.     $field_value = get_post_meta($post->ID, $field, TRUE);
  15.     $content .= ' '. ( is_array($field_value) ? implode(' ', $field_value) : $field_value );
  16.   }
  17.   return $content;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement