Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


How to create relationship between post types

Hi everybody and Zac Gordon, I'm trying to create a Complex Custom Post Type, when I say complex it's because, I need connect multiple Custom Post Types in just One. Could anybody give any advice to create this CPT in WordPress?

2 Answers

Kevin Korte
Kevin Korte
28,148 Points

What kind of relationship? More context here would be helpful for me.

Hi Kevin, well, I need create a relationship between two CPT, for example, I have a CPT named Products and other CPT named Type Product, I need to relate Products with Type Product, to specify what type of product is my product. I hope be clear, thank you.

Francois Dejardin
Francois Dejardin
1,778 Points

You could create a Relationship Custom Post Type, add metas to post which contain the IDs of the other Custom Post Posts. So you will have all the Relationship posts with the different other Custom Posts references and you could get back these Ids with a get_post_meta.

Hope this will help ;)