Support

Account

Home Forums ACF PRO querying multiple post relationships?

Solved

querying multiple post relationships?

  • Hi- i’ve got a bit of a tricky question here. what i’ve got is 2 custom post types i’m trying to link. One, lets call it Seminars has an ACF post object field called ‘speakers‘ allowing you to select Multiple posts from the second post type- ‘Speakers‘ and returning the post IDs.
    this part works fine, I can retrieve linked speakers and display them in the single ‘Seminars‘ post template as expected. Here’s the tricky part.

    what i want to do in the single post template for the ‘Speakers‘ post type, is to get the ID of the current post (easy enough) and run a query on the ‘Seminars‘ post type to check for posts where the current post’s ID is selected in the ‘speakers‘ field. The issue i’m having is that because it’s a multi-select, it doesn’t seem to work when there’s more than one entry.

    i’d got this far:

    $id = $post->ID;
                 $args = array(
                     'post_type'=>'seminars',
                     'meta_key' => 'speakers',
                     'meta_value' => $id
                 );
                 $eventquery = new WP_Query($args);
                 if ($eventquery->have_posts()) :
        while ($eventquery->have_posts()) :
            $eventquery->the_post();
        endwhile;
    endif;
  • You need to do a “LIKE” meta query. See the single-location.php section of https://www.advancedcustomfields.com/resources/querying-relationship-fields/

  • Thanks John! that looks like what i’m after- thanks for the headsup- will give it a crack this afternoon and see how i get on..

  • @john Huebner- absolute legend, that worked like a charm!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.