Skip Navigation

[Resolved] Display objects that are in a relationship, that in turn are in a relationship

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 1 reply, has 2 voices.

Last updated by Nigel 1 year, 1 month ago.

Author
Posts
#2661321

I have three custom post types clinics, therapists, and treatments.

Therapists can be connected to clinics, and therapists each can have treatments connected to them.

Can I display a list of clinics, and filter it by treatments offered by the therapists there, without directly assigning treatments to clinics? The reason I want to do this is because treatments available at a clinic are really defined by what therapists are there, and what accredidations they have. Ideally I could change what clinics a therapist is connected to, and the treatments offered by those clinics would reflect those changes automatically. I would need this type of filtering to be possible both as a search capacity(patients could filter to only show clinics that have therapists who offer specific treatments), and as a defined filter(On each treatment page, only show clinics that have therapists who offer that treatment).

Is there a scalable way this is done, perhaps by accessing relationship of child posts, or intermediate posts?

I previously received help to filter results in a view loop, which works very well for one use case I needed, but I'm not sure it would scale with search results, or grid views.

#2661625

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I'm afraid Toolset relationships don't support this scenario. When it comes to filtering you can only filter by fields that belong to the content being filtered, or filter based on connections to a specified post.

In your case if you are displaying clinics then you can only filter by clinic fields, or you could filter clinics to only show those connected to a specified therapist.

If treatments were directly connected to clinics it would be possible to filter clinics connected to a specified treatment.

Perhaps a solution would be to use the Post Relationships API, hooking into whenever a therapist post was updated, and setting clinic<<>>treatment connections based on queries of what treatments are connected to the therapist and making the same connections to each of the clinics the therapist is connected to.

See https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

#2665169

Awesome, thank you. I will build out a solution using the API.