Skip Navigation

[Resolved] Best Practice for Post Relationships

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a Content Template for CPT A, and I would like to show all the related child CPT B posts inside that Content Template.

Solution: Use a parent / child relationship to link CPT A and CPT B. Create a View of CPT B, filtered by post relationship, where the parent post is set by the current page. Insert this View into a Content Template assigned to CPT A.

Relevant Documentation:
https://toolset.com/documentation/user-guides/creating-post-type-relationships/
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#622243

Tell us what you are trying to do?
So, I have create a new custom post type called 'dog breeds' I have successfully created all the breeds that I want. And now I am making a second custom post type called 'dogs for sale'

I want people to register for my site, and then upload their own 'dogs for sale' posts...

I am wondering what is the best way to link Breeds and DOGS for sale... I want my content template for dog breeds to display a slider or post loop at the bottom of the relevant dogs for sale, JUST FOR THAT BREED.

The person who makes the submission can select from a drop down list of breeds to register that dog against, thus linking the two post types.

Can you help please?

Here is an example:
hidden link

What is the link to your site?
hidden link

#622268

Hi, if a dog for sale can only belong to one breed, then a parent / child relationship between breeds and dogs is logical. However, if a dog can belong to multiple breeds, then you cannot use a parent / child relationship because a child can only belong to one parent in any single post type. There are other options in that case, like using a taxonomy or using a many-to-many relationship.

I want my content template for dog breeds to display a slider or post loop at the bottom of the relevant dogs for sale, JUST FOR THAT BREED.
No problem. If you use a parent / child post relationship as discussed above, then you can create a View of Dogs for Sale, filtered by post relationship, where the parent post is the page where the View is placed. This will loop over all Dogs for Sale that are child posts of the current Breed. Insert that View in your Content Template for Breeds to have it appear on each Breed page.

#622668

Thanks for your help thats just what i needed

#622675

Hi, sorry can you explain. Which will be the parent and which the child? The breed the parent and then all children are the dogs for sale under that breed?

How can I use a front end form to allow people to automatically give their dog for sale the right parent?

Thanks

#622713

Hi, sorry can you explain. Which will be the parent and which the child? The breed the parent and then all children are the dogs for sale under that breed?
Breed will be the parent and Dog will be the child, because a Breed can include multiple Dogs but a Dog can only belong to one Breed.

How can I use a front end form to allow people to automatically give their dog for sale the right parent?
Here's a document that describes how to create child post forms:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/
The document also describes how to use a CRED Child Post Link to automatically set the correct parent post.