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?
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.
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.
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.
Of course. So its safe to say it will not be in the next release?
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.
No problem, let me know if you get stuck.
Thank you Christian. I will do!
I'm standing by for your update.
I am going to try and achieve this another way Christian.
Thank you for all your help with this.