Support

Account

Home Forums ACF PRO ACF and WP Search Reply To: ACF and WP Search

  • Hi John,

    Thank you for your speedy reply. I do have to apologize, I just realized I was thinking of another post type when explaining my issue.

    On the People page template, instead of a repeater with a post object sub field. I have just a post object field that allows multiple selections. Then in my template file I was using a foreach loop to display each person selected.

    I tried to edit your code snippet for my correct situation, but think I’m doing something wrong as it’s still not returning any results. And yes, for the people cpt, the title is what contains the person’s name.

    add_action('acf/save_post', 'copy_persons_to_people', 20); // priority 20 runs after acf has saved content
    function copy_persons_to_people($post_id) {
      // we need to create a new meta key to hold the list of people
      // this is the meta key you'll use to set up the search of this field
      $meta_key = 'related_peoples';
      // clear this field if it exists for this post
      // need to start fresh each time
      delete_post_meta($post_id, $meta_key);
      // see if there are any related people
      $persons = get_field('team_members', $post_id);
      
      foreach ( $persons as $person ) {
    	  add_post_meta($post_id, $meta_key, $person->post_title, false);
      }
    }

    On the page template, the acf field for the post object is called ‘team_members’.

    Thanks again for your help, I really appreciate it.