Support

Account

Home Forums ACF PRO Relationship between 3 post types Reply To: Relationship between 3 post types

  • I am not exactly clear on the relationships but I gather that it’s something like
    Post Type 1 <> Post Type 2 <> Post Type 3
    and you want to show either Post Type 1 on Post Type 3 or vice versa.

    To eliminate a lot of extra querying, the first thing I would do is to make these relationships bidirectional. This can be done by coding, although this doc is for bidirectional relationships on the same post type https://www.advancedcustomfields.com/resources/bidirectional-relationships/, or you can use a plugin like https://wordpress.org/plugins/post-2-post-for-acf/ and your can find some additional resources in my github repo https://github.com/Hube2/acf-filters-and-functions.

    Then instead of doing queries you just get what you need without doing all the reverse relationship queries.

    
    // get relationship field on current post
    $related_x = get_field('1st relatioship field name');
    foreach ($related_x as $related_x_post) {
      $related_y = get_field('2nd relationship field', $related_x_post->ID);
    }