Support

Account

Home Forums ACF PRO Search in relationship field Reply To: Search in relationship field

  • Even plugins that alter the WP search cannot do this. The problem is that the content you want to search is save to a different post. When WP searches it returns the post where the content is located.

    There may be a premium search application somewhere that might be able to do this, but I have never heard of one.

    The only way that this could be accomplished would be to copy the content from the related posts into the post you want to return the results for.

    For example:
    Please not that this is just an example, I do not know if this will meet your needs exactly or how it will interact with the rest of your site/code

    
    add_action('acf/save_post', 'copy_related_content', 20);
    function copy_related_content($post_id) {
      remove_filter('acf/save_post', 'copy_related_content', 20); // prevent infinite loop
      $posts = get_field('your-relationship-field', $post_id);
      if ($posts) {
        $content = '';
        foreach ($posts as $post) {
          $content .= ' '.$post->post_content;
        }
        $post = array(
          'ID' => $post_id,
          'post_content' => $content
        );
        $result = wp_update_post($post, true);
      }
      add_action('acf/save_post', 'copy_related_content', 20); // replace filter
    }