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);
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF PRO’s Flexible Content field allows you to create smaller pieces of UI and compose them into whole flexible patterns. In our latest article, we show how to use it to create swappable site sections and integrate it all in a theme.https://t.co/ZRocH8oJSp
— Advanced Custom Fields (@wp_acf) January 24, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.