I have the following custom post types:
- Countries
- Cities
- Event Locations
- Events
and the following relationships:
- Countries - Cities = 1 to many - shortcode= "country-city"
- Cities - Event Locations = 1 to many - shortcode= "city-event-location"
- Events - Event Locations = many to many - shortcode= "event-event-location"
and in a view that displays the events I like to display the country name from CPT Countries
so i followed your tutorial: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/
I'm able to display the the city name like this, as it is a grand parent - but somehow I am missing something to get the country name too which is a grand grand parent 🙁
I made the following Templates:
for the Event
<div>
<p>
<h3>[wpv-post-featured-image][wpv-post-link]</h3><br>
Start Date: [types field='event-start-date' style='text' format='F j, Y'][/types]<br>
Ending Date: [types field='event-ending-date' style='text' format='F j, Y'][/types]<br>
Location: [wpv-post-title item="@event-event-location.child"]<br>
Address: [types field='event-location-address' item='@event-event-location.child'][/types]<br>
City: [wpv-post-body view_template="city-name" item="@event-event-location.child"] - <br>
Country:[wpv-post-body item="@event-event-location.child" view_template="country-name"]<br>
ZIP: [types field='event-location-zip-code' item='@event-event-location.child'][/types]<br>
Website: [types field='event-website' target='_blank'][/types]
</p>
</div>
to display the City Name:
[wpv-post-title item="@city-event-location.parent"]
to display the Country Name:
[wpv-post-title item="@country-city.parent"]
But looks like I did something wrong here.
Any hints are highly appreciated
I just wonder if this is impossible to do with Toolset or did i set up things the wrong way ?
Hi, based on your description I think the issue is here:
- Events - Event Locations = many to many - shortcode= "event-event-location"
Country:[wpv-post-body item="@event-event-location.child" view_template="country-name"]
The problem with this approach is that the Events to Event Locations relationship is many-to-many. So in any single Event, there may be many different related Event Locations. It's not possible to determine to which one you are referring in this instance, and the shortcode isn't set up to handle multiple results. You'll need to replace this template shortcode with a View of related Event Locations with a post relationship filter. This will give you the ability to add filters and display information about a single event location, or create a list of related event locations.
Let me know if you have additional questions about that.
Hi Christian
Thanks a lot for your reply and explanation.
If i understand it right you mean to replace the view_template with a complete new view ?
But im still puzzled about how to set up the whole thing or connect the grand grand parent in this to get the Country name.
The hierarchy is the following:
- Country (Grand Grand Parent)
-- City (Grand Parent)
--- Event Location (Many to Many)
---- Event
So far i can get the proper event location and city - but not the country
So I tried to make a view that should display the Country Name (post title of CPT countries) but somehow still dont understand how to set it up properly as all what I tried returns a not found
Please let me know if its easier for you if i send you some site credentials for having a direct look?
Hi Christian
I found it 🙂 YAY
I made a view that "Select posts in a Events at Event Locations relationship that are a related to the current post in the loop."
and then i added there the template: view_template="country-name" and all works like a charm.
Thanks for guiding me toward the right direction 🙂
Best regards, Peter
My issue is resolved now. Thank you!