Skip Navigation

[Resolved] Custom post type with two parents of the same type?

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

Problem:

The issue here is that the user wanted to assign 2 parents to a child post. The Parents are of the same CPT.

Solution:
This can be done by using a Many to Many relationship. Please take a look at the link below for more information on this.
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/

This support ticket is created 6 years, 11 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by gavinS-2 6 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#608880

I am trying to do something that is possibly a bit strange.

I'm working on something where people can book items out, but when they book an item, the system should suggest other items that people usually book with this item. eg. if you book a camera, you probably also want a tripod, some lenses and a bag.

So it seems what I'm trying to do is create a many to many relationship with two parents of the same type (items). My first thought was to create an intermediary post type, which would have a field for the original item, and then another field for an 'accessory item' and a third field for the amount of accessory items. eg if you book a certain camera, then you probably want to book two batteries that fit the camera, one tripod and 3 memory sticks. Each of these 'accessories' would have a post with the original item id, the accessory item id and the amount. So then when someone booked an item, I can check the intermediary posts to see if there are any accessories for this item and how many are recommended.

It doesn't seem possible though to have two parents of the same type. Is there another way I can do this?

#608919

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gavin,

Thank you for contacting our support forum.

This seems to be a many to many relationship as you mentioned.

For this I would recommend you try using our Latest Types Beta as it makes creating M2M relationships alot easier.

You can download it by going to the link below.
https://toolset.com/account/downloads/

Then selecting "Beta" from the dropdown list.
Below you can see a short demonstration of how this works.
https://toolset.com/2017/12/types-and-views-betas-with-many-to-many-relationships/

Please let me know if this helps.
Thanks,
Shane

#609198

Hi Shane

Thanks, but will this work if it is a many-to-may relationship between the same post type? Ie a many to many relationship between items and items?

#609445

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gavin,

I believe I understand what you mean now. Unfortunately no this is for many to many between different Post types.

I believe wordpress only supports one to many within the same post types.

Thanks,
Shane

#610586

Thanks Shane

I managed to find another way to do what I'm doing, just by storing a post number in another field.