Title: Indexing ACF fields
Last modified: September 1, 2016

---

# Indexing ACF fields

 *  Resolved [VFHwebdev](https://wordpress.org/support/users/vfhwebdev/)
 * (@vfhwebdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/)
 * It looks like Relevansi isn’t indexing the custom fields I set up through Advanced
   Custom Fields.
 * I’ve added the field names as a comma separated list to the “Custom Fields to
   Index” option field but they still don’t seem to be included in the search results.
 * Is there another setting I need to check? Is there a known issue with custom 
   fields set up through “Advanced Custom Fields”?
 * Thanks
 * [https://wordpress.org/plugins/relevanssi/](https://wordpress.org/plugins/relevanssi/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [VFHwebdev](https://wordpress.org/support/users/vfhwebdev/)
 * (@vfhwebdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611521)
 * A little more info. On further inspection, it looks like some of my fields are
   getting indexed. The ones that aren’t all appear to be “relationship” ACF fields.
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611560)
 * How should Relevanssi index the relationship field?
 *  Thread Starter [VFHwebdev](https://wordpress.org/support/users/vfhwebdev/)
 * (@vfhwebdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611600)
 * At a minimum it’d be great if it could index at least the post title of related
   posts.
 * Here’s an example use case.
 * We’re running a web site for a festival. The festival has events and speakers,
   both of which are custom post types. There’s a relationship field that connects
   speakers with the events they are speaking at.
 * Right now, when you search for a speaker by name, you don’t get the events at
   which they are speaking.
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611637)
 * Ok, that’s definitely something you need to teach Relevanssi to do. Fortunately,
   somebody else has asked this before, and [I have some instructions available in the KB](https://www.relevanssi.com/knowledge-base/advanced-custom-fields-relationship-fields/).
 *  Thread Starter [VFHwebdev](https://wordpress.org/support/users/vfhwebdev/)
 * (@vfhwebdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611672)
 * Thanks! I’ll take a look and see if I can apply it to my situation. I appreciate
   the quick and helpful response.
 *  Thread Starter [VFHwebdev](https://wordpress.org/support/users/vfhwebdev/)
 * (@vfhwebdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611686)
 * I’m making progress but there are a couple of things about the example I’m having
   trouble understanding.
 * Here’s the example for reference:
 *     ```
       add_filter('relevanssi_content_to_index', 'beautymed_add_product', 10, 2);
       add_filter('relevanssi_excerpt_content', 'beautymed_add_product', 10, 2);
   
       function beautymed_add_product($content, $post) {
   
           $tplName = get_post_meta( $post->ID, '_wp_page_template', true );
   
           if ($tplName === 'template-types.php') {
   
               $products = get_field('produits');
   
               foreach ($products as $product) {
                   $content .= get_field('description', $product->ID);
                   $content .= get_field('infos', $product->ID);
                   $content .= get_field('conseils', $product->ID);
               }    
   
           }
   
           return $content;
       }
       ```
   
 * And here’s what I’m trying to do.
 *     ```
       add_filter('relevanssi_content_to_index', 'bookfest_add_participant', 10, 2);
       add_filter('relevanssi_excerpt_content', 'bookfest_add_participant', 10, 2);
   
       function bookfest_add_participant($content, $post) {
       	$participants = get_field('participants', $post->ID);
       	if($participants){
       		foreach ($participants as $participant) {
       			$content .= get_the_title( $participant->ID );
       		}
       	}
           return $content;
       }
       ```
   
 * Checking for the page template isn’t working for me. I guess my theme is using
   the default template. So I thought it made more sense to check for the existence
   of the Participants field. But this isn’t working. I tried removing the “if (
   participants)” condition and still no dice. Any suggestions?
 *  Thread Starter [VFHwebdev](https://wordpress.org/support/users/vfhwebdev/)
 * (@vfhwebdev)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611687)
 * I think I may have found the problem. I have more than one participant per event
   and I think the additions to $content need a space between them.
 *     ```
       add_filter('relevanssi_content_to_index', 'bookfest_add_participant', 10, 2);
       add_filter('relevanssi_excerpt_content', 'bookfest_add_participant', 10, 2);
   
       function bookfest_add_participant($content, $post) {
       	$participants = get_field('participants', $post->ID);
       	if($participants){
       		foreach ($participants as $participant) {
       			$content .= get_the_title( $participant->ID );
                               $content .= " ";
       		}
       	}
           return $content;
       }
       ```
   
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611706)
 * Yes, adding spaces between the entries is a good idea.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Indexing ACF fields’ is closed to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=3529670)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)

 * 8 replies
 * 2 participants
 * Last reply from: [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/indexing-acf-fields/#post-7611706)
 * Status: resolved