Hi, I'm developing a site using Types and Views, and have CPTs setup like this:
Parent PT
-- Child PT 1
-- Child PT 2
-- Child PT 3
-- Child PT 4
-- Child PT 5
The child post types are actually very similar (as in, they're all twins, but not identical ones), so I cannot (or should I?) group them into a single post type, and each child post type can have many parent posts, so it's clear that I need an intermediate object.
My first question is, should I use a single intermediate CPT to link parent and child posts together, or would I need a separate CPT for each child?
And secondly, I need a way (from my parent CPT) to list all its children, regardless of child CPT, grouped together. Is there a (sane) way to do that?
Thanks in advance.
Hi Karim,
Q1) It would be a huge work to "separate CPT for each child", I suggest "use a single intermediate CPT to link parent and child posts together",
Q2) Yes, It is possible within Views, please check the document
Creating and Displaying Many-to-Many Post Relationships
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/
section:
Displaying Many-to-Many Relationships Using Views
Hi Luoy, thank you for your reply.
For question 1, I've deleted all the separate CPTs and made a single intermediate one as you suggested.
As for question 2, I still have a question on how to do this (actually, a question and an observation):
Q2.1) Suppose I have the following post types:
Software Provider, Company, Team, Program. A Software Provider has many Programs, and a Company has many Teams. So far so good. But, when I view a particular Software Provider, I want to be able to list which Companies use Programs that belong to it. Likewise, if I view a particular Program, I'd like to list the Companies that use it. Does that make sense? What would be the best way to do this?
Observation: I've been following the guide you linked to, but since (I think) the documentation was made for an earlier version of Views, I was confused about how to add the filter, since it mentions parents. The correct filter should be for Child posts, where the option "Post where this View is inserted" is present.
Thanks in advance for your help.
In your case, I suggest you try create many to many relationship between post type Programs and Company.
1) if I view a particular Program, I'd like to list the Companies that use it
please follow our document to display the Companies list
Displaying Many-to-Many Relationships Using Views
2) when I view a particular Software Provider, I want to be able to list which Companies use Programs that belong to it.
You can create a nested view,
parent view list all Programs belong to current Software Provider
child view list as 1)
3) Observation
Yes, you are right
The correct filter should be for Child posts, where the option "Post where this View is inserted" is present.