Skip Navigation

[Resolved] Query intermediary and search parent or query parent and filter by intermediary

This support ticket is created 5 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
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)

This topic contains 10 replies, has 2 voices.

Last updated by Ben 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1237853

Ben

I have CPTs of "Places" and "People", they are linked by a M2M relationship that has a field of "Location Type".

On a page of "Places" I would like to be able to display a list of related "People" and filter by the custom field of "Location Type" (the relationship field - attached to the intermediary post).

At the moment I have a View that queries the intermediary posts in this relationship. I can display the related "People" title instead of the actual intermediary post title. When I use this method I can filter via the custom field of "Location Type" no problem, but adding a search to this view doesn't work because of course it is searching for the intermediary post type titles and not the related post titles which are being displayed.

If I use the other method and query "People" then the search will work but I cannot seem to be able to filter via the relationship field.

So, neither way that I have found allows me to do both. Is there a way that I can make this work?

Or are there any known workarounds or alternatives that could solve this?

#1237911

There's not currently a simple way to search and filter a View of post type "A" by post type "B", regardless of their post relationships. We are planning to enhance that part of Views filters but that's not quite ready yet. Instead, I guess you could automatically copy the parent Person post title into a custom field in the intermediary post, then use Relevanssi to index that custom field in text searches.
https://toolset.com/documentation/user-guides/searching-texts-custom-fields-views-relevanssi/

The post relationships APIs toolset_association_created and toolset_before_association_delete can be used to automate the copying process:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_before_association_delete

If that workaround sounds acceptable, I can help if you get stuck using the APIs.

#1237922

Ben

Thank you for the suggestions Christian!

Do you have any details of ETAs for that enhancement of Views filters? I'd rather not get into copying the post titles and extra custom fields if I can help it, especially if this is likely to be a feature at some point relatively soon.

If not, then I can have a try at implementing this.

#1237926

I don't have an estimate available right now, so my best advice is to count on this feature notbeing ready relatively soon. Development priorities are constantly shifting and it's hard for us to predict beyond the next release.

#1237927

Ben

Of course. So its safe to say it will not be in the next release?

#1237930

As far as I know, yes.

#1237931

Ben

Thank you for confirming Christian.

Let me have a test of this other solution and see if I can make it work how I need it to.

#1237935

No problem, let me know if you get stuck.

#1237943

Ben

Thank you Christian. I will do!

#1237944

I'm standing by for your update.

#1238022

Ben

I am going to try and achieve this another way Christian.

Thank you for all your help with this.