Skip Navigation

[Résolu] Displaying of grandparent values

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I would like to be able to display information from related posts, but the shortcodes don't seem to be working correctly.

Solution: If a relationship is many-to-many, you must use a View to display information from related posts.

This support ticket is created Il y a 5 années et 1 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Ce sujet contient 5 réponses, a 2 voix.

Dernière mise à jour par peterS-14 Il y a 5 années et 1 mois.

Assisté par: Christian Cox.

Auteur
Publications
#1360481

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

#1360593

I just wonder if this is impossible to do with Toolset or did i set up things the wrong way ?

#1360881

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.

#1360897
View for related Country 002.JPG
Vie for related Country.JPG

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?

#1360921

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

#1360925

My issue is resolved now. Thank you!