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

  • The problem is that what you’re searching for is content associated with another post. The only thing that’s on the “people” page are the post IDs of the posts that contain the content. As far as I know, there isn’t a search application of any kind (other than search engines like google) that will search this related content.

    What you need to do is to make the content of those people pages part of the post that you want to return results for. For example, let’s say that the title of the person post is their name and you want the name searchable on the people page.

    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
      if (have_rows('repeater_field_name', $post_id)) {
        while(have_rows('repeater_field_name', $post_id)) {
          $person = get_field('sub_field_name');
          // assuming the above returns a post object
          // add the title of the person post to the post meta of this post
          // the last parameter set to false means this meta key can have
          // multiple values
          add_post_meta($post_id, $meta_key, $person->post_title, false);