Skip Navigation

[Closed] Parent and child same CPT

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 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 5 replies, has 2 voices.

Last updated by Mateus Getulio 1 year, 2 months ago.

Assisted by: Mateus Getulio.

Author
Posts
#2647189

Hi,
I've created a CPT named "Contents". A few "Contents" are bigger than other. For example, a Content can be "Compilation 1". Inside this "Content", you can find "Article 1", "Article 2", and "Article 3". These are also "Contents".

I'd like to set "Compilation 1" as parent of the three other contents, and these contents, as child.

Why I don't create two CPTs?
Because I need a page with a list, where all Contents appear, it doesn't matter they are parents, or there are contents without child or parent (which are the most cases). Also I need to have a form for searching ALL contents. And I need all contents to have the same Custom Fields.

Why I need parent-child "relation"?
I'd like to show, in content template, if it has any childs, or if it has any parent. For example in a "child" content, a message "It appears in: Parent".

How can I create this relation?
I'd prefer not to use hierarchy. The hierarchy URL created is bad for me.

Is it possible?
Thanks,

#2647681

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

Thank you for contacting our support.

You can establish parent-child relations in Toolset without relying on the hierarchical structure. Create a “Contents” Custom Post Type (CPT) and establish relationships using Toolset’s Relationship Field. This lets you link child contents to their respective parents.

Within Toolset, design templates to visually represent these relationships. For instance, use shortcodes or blocks to display parent content on child templates and list associated child contents on parent templates.

To display all contents and their relationships, create a Toolset View listing all “Contents” CPTs, irrespective of their relationships. Also, incorporate a Toolset search form to facilitate content search across all parents and children, displaying relevant Custom Fields in the results.

Within the CPT settings, make sure that your CPT is non-hierarchical to avoid the unwanted URL format, crafting a custom URLs with custom code if necessary. This approach, using Toolset’s Relationship Field, should allow effective relationship representation while maintaining a preferred URL structure and meeting your requirements.

Can you please give it a try and let us know if it works for your scenario?

Thank you.

Mateus

#2648617

Hi Mateus,
my WordPress is in Spanish, and can't find Relationship Field. I find "Post reference" Field, which lets you reference a post, that is not the same type as my CPT. So this does not work for me.

Relationships are not an option, as you can't create relation between same class CPT, "Self-join relationship".

Can you help me to find this option?

Thanks!

#2648867

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

Thank you for your reply.

I apologize for the misunderstanding and thank you for your patience. It seems that, currently, Toolset does not support self-join relationships; it’s in the backlog for future implementation, but there is no ETA for it yet.

In summary my suggestion involved you using two CPTs (eg.: Content and Compilation)linked with the relationships disabling the 'hierarchical' option for them to try to avoid the issue with the URL. And then the CPT Compilation could have the custom field 'articles' added to them and given the relationship they'd be linked to the Content CPT.

Please check our documentation on the relationship and related posts for reference:

- https://toolset.com/course-lesson/what-are-post-relationships-and-how-they-work/
- https://toolset.com/course-lesson/how-to-set-up-post-relationships-in-wordpress/#how-to-connect-related-posts

Alternatively, depending on how both compilations and articles need to be designed, compilation can be a repeating field inside Content, having multiple articled added to it when you create a post of that CPT. If you manage to design you CPT like that, you might eliminate the need of a relationship.

Please check this tutorial on how to create repeating fields groups using toolset: https://toolset.com/course-lesson/creating-and-displaying-repeatable-field-groups/

I hope it helps you achieve what you need to.

Thank you

Mateus

#2650019

Hi Mateus,
it's just impossible to use two different CPTs. All these items are Content. I'll try a workaround, creating some taxonomy to relation all the contents that belong to a "father".

Any case, please consider being able to create self-join relationships. I can imagine a lot of cases where this is necessary.

Thank you,

#2650193

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

I 100% agree with you, it is going to be a very useful addition to Toolset when it gets added.

And I apologize for not being able to be more specific about an ETA.

Best regards,

Mateus

The topic ‘[Closed] Parent and child same CPT’ is closed to new replies.