Skip Navigation

[Resolved] Conditional relationships

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

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by Puntorosso 6 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#905489

Hi,
I am playing around with the tremendous possibilities offered by the new update.
I have a doubt about how to display a related post conditionally, and I don't know if it's possible using only Toolset's new relationships or I have to code it.

As example, lets build a database of shore excursions for cruises.

- A Cruise has a departure and an arrival time
- An Excursion has also a departure and arrival time

What I would like to achieve is that once the customer select his Cruise, Toolset display only the Excursions available in their departure/arrival time slot.

To be clear: if the Cruise X is coming 10am and leave 5pm, only the excursion which start from the port AFTER 10am and return to the port BEFORE 5pm should be displayed.

Any help is really appreciated.

Thanks

Best

P.S.: By the way, incredible update! Well done!

#905506

I assume you refer to the Front End and mean to build a Custom Search for your users to choose Cruises and display to them only Excursions that are within that Cruise, and a given Time?

You can do that by a Parent/Child relation which you use to filter the Excursions belonging to the chosen Parent (Cruise).
This happens in a View that queries the Child Post (Excursions).

This way you can then as well add a Date Custom Filter, that is possible to set to filter between 2 (a max and min) data value.

1. Create a View that queries Excursions
2. Add a Custom Filter that allows you to select a parent Cruise to search by, for example:

[wpv-control-post-ancestor type="multi-select" ancestor_type="parent_type_slug@parent_type_slug-other_post_type.parent"]

3. This as well automatically adds the Query filter:

Select other_post_type in a Parent Type Other Post Type relationship that are related to the Post with ID set by the URL parameter wpv-relationship-filter.
eg. <em><u>hidden link</u></em>

4. Now if you have existing relationships, and insert this View to a page, you can choose from a filter the Parent Post (the Cruise, in your case) and it will return all child posts (Excursions that are connected to the Cruise).

To add a Data filter, you can use a Custom Field where you store the dates, for example, and use that as a filter.

https://toolset.com/documentation/user-guides/filtering-views-query-by-date/
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

I hope this answers the questions!
If not, please let me know 🙂

#905565

Great, thanks!

Now I start to understand the full power of Toolset 😉
It was confusing to me because I come from a Filemaker's world, where the conditional parameters are integrated in the relationship itself.

Now I have only to solve the problem with the time fields, but I open another ticket so it's more transparent for other users.

Thanks a lot for your help.

Best