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.
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?
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".
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:
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.
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.