Skip Navigation

[Resolved] Querying Ancestor Content Types

This support ticket is created 7 years, 5 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.

This topic contains 8 replies, has 2 voices.

Last updated by jamesC-14 7 years, 4 months ago.

Assigned support staff: Beda.

Author
Posts
#298793
Wordpress Content Type Relationship 1.jpg

I am trying to provide a list of links to "uncle" content types on a content page. I've attached a picture explaining the content structure I'm using and what I'm trying to do. If it's not clear please let me know and I'll try to explain in more detail.

Thanks in advance!

#299351

Thank you for contacting us here in the Support Forum

I think you could reach that goal with some Views, which you'll be rendering on Post Type D

I assume following scenario according to your screenshot:

1. You have a Custom Post Type D, and of course many posts of that type
2. You have Custom Post Type B and C, also with many posts of that type
3. You want to render your Custom Posts Type D with links to all Custom Posts Type B and C

You could now create (i.e.) 2 Views:

1. View A is sorting Custom Post Types B, and displays (i.e.) Title with link only (to those posts)
2. View B is sorting Custom Post Types C, and also only displays Title with links (to those posts)
https://toolset.com/documentation/user-guides/views/

Now you can either create a Content Template for all Custom post Types D, and insert he previously created Views into it, or insert those Views directly in some Custom Post Types D, if you perhaps don't want all Post Types D to have links to the other Custom Posts
https://toolset.com/documentation/user-guides/view-templates/

You can insert your Views wherever you want, if i.e. you are using Layouts to design your Site, you can also insert them there.

You could also use Views inside Views.
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

Please let me know if you have further questions regarding the issue mentioned in this Thread
and let me know if the above solution works for you, I look forward to your reply!

Thank you

#299392
Wordpress Content Type Relationship 2.jpg

Thank you for the reply! I think I did a poor job of explaining the entire infrastructure of what I'm building. The content structure you see on the first diagram is one of many structures like that on the site. I've added a new diagram to help explain this. To explain further, I do not want a link to EVERY content type B on EVERY content type D - I only want links to content type B's that share a common content type A ancestor with the content type D in question. Does that help clarify the problem?

#299420

I am preparing a solution for this, and would need a specification:

Has Content Type A, B, C and D to be the SAME on both Content Structures, or could it be like this:
Structure 1:
Content types A, B, C, D (Custom Post Type named A, B, C, D)
Structure 2:
Content Type A1, B1, C1, D1 (same hierarchy but different Custom Post Types, namd A1, B1, C1, D1)

Note:
On both Content Structures, the Content Types would be the exacts same (settings) but would have different names, to be detailed, alike "duplicated" Custom Post Types, but using different names + Slugs
Creating posts in Content Type A, would obviously not create posts in Content Type A1.

Since you wont link across the Content Structures, I think this could fit your needs?

In this case, the solution would be achievable with nested Views.

In the case on both Content Structures you want to sue the exactly same Custom Post Types, I need to dig deeper into it.
We need to "Differentiate" the Posts of those content types to link them accordingly

Please can you let me know if solution #1 would fit your needs?

Thank you for your collaboration and patience

#299423

The content types will be the same across content structures. For example, Content Type A is a single content type, regardless of where it appears on the site.

Thanks!

#299678
Child-Parent m.t.m.jpg

Thanks for the Details

I have attached a screenshot.
On the left Content Structure is what you need, meaning the links-to.
On the right Content Structure, is illustrated how you would need to set the parent/child relation ships

This is also explained in detail here:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/
https://toolset.com/faq/how-do-i-associate-one-child-with-several-parents-of-the-same-type/

As previously thought of, a many-to-many relationship is most probably what you need to achieve this.

If you have a look at the example in the DOC, you'll see a similar structure, they just use different terms, such as Event-Apparence-Band, or Musician-Album-Song

All of those Custom Post types have a many-to-many relationship, means, the same musician has many albums, many of his songs are on a few albums of his, and perhaps even on albums that are not made by him. etc.

You would then need to query the intermediary post type in the view, and use the id attribute to display fields from both of the parents

The clue is, to detect the proper intermediary Post Type, to make it Parent of the others.

(you can arrange your parent/child relationship and the view as per your needs, of course)
My Screenshot is just a example built on the structure I pulled from your Screenshot.

there is also the possibility to display a post from content type D by using the ID attribute to query values from the related content type B (or as per your needs)

[wpv-post-title id="$content-type-b"]

https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

Please let me know if you have further questions regarding the issue mentioned in this Thread
and let me know if the above solution works for you, I look forward to your reply!

Thank you

#299806

The relationships between post types are currently that Post Type A is the parent of Post Types B & C, and Post Type C is the parent of Post Type D.

It looks like the diagram is suggesting that Post Types A & D should be children of Post Types B & C - is that what you are saying?

#300058

Thanks for the Details

The clue is, to detect the proper intermediary Post Type, to make it Parent of the others.

You can choose the intermediary Post Type as per your needs, you could even create a new one, if you prefer this.

The Idea of a many-to-many relationship is, that you connect 2 "main" post types using a third Post Type, which is not necessarily "related" to the other two by meaning.

As in the example here:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/

The intermediary Post Type "Appearances" does not specifically relate to Events or Bands, but it helps connecting the both ends in a many-to-many relationship.

You would need to find a correct intermediary element, to get this properly to work the way you want.

There is also the possibility to display a post from content type D by using the ID attribute to query values from the related content type B (or as per your needs)

The only other possibility is to add Links using Post ID's, but this requires manual work, such as adding links for each newly added Post per Post Type.

I hope I explained this well!

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you

#300869

Thanks for the reply. I don't think the many-to-many relationship really describes what I'm trying to do. I'm going to have to look at other options for achieving this functionality.