SHARE
TWEET

ACF Gallery and Relevanssi Filter...

a guest Jun 4th, 2016 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. I tried this in functions.php first:
  3.  
  4. add_filter('relevanssi_excerpt_content', 'custom_fields_to_excerpts', 10, 3);
  5. function custom_fields_to_excerpts($content, $post, $query) {
  6.     $images = get_post_meta($post->ID, 'gallery', true);
  7.     if( $images ) {
  8.         foreach( $images as $image ) {
  9.             $content .= " " . $image['title'];
  10.             $content .= " " . $image['caption'];
  11.         }
  12.         return $content;
  13.     }
  14. }
  15.  
  16.  
  17. Then, I tried this version (unfortunately, neither worked):
  18.  
  19. add_filter('relevanssi_excerpt_content', 'custom_fields_to_excerpts', 10, 3);
  20. function custom_fields_to_excerpts($content, $post, $query) {
  21.     $images = get_field('gallery', $post->ID);
  22.     if($images){
  23.         foreach( $images as $image ) {
  24.             $content .= " " . $image['title'];
  25.             $content .= " " . $image['caption'];
  26.         }
  27.     }
  28.     return $content;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top