[Resolved] Create a custom search filter using a relationship
This support ticket is created 6 years, 3 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Tell us what you are trying to do?
I have two custom post types. The first is an expert and the second is an event. The event has a custom field: event date. The two post types are related in a many to many relationship. I would like to display all experts but add a search filter of events dates.
Is there any documentation that you are following?
Watched some tutorials and read the how to document.
The feature of filtering one type of post by fields of another type of post is not yet supported, but is the main feature that will be added in the next Views development cycle, starting soon.
In the meantime you can only filter something by its own properties, although you can get halfway there with M2M relationships by filtering based upon the relationship fields.
So if you have speakers appearing at events and manage this with an "appearances" relationship, you could store a date field for the appearance. It would then be possible to filter speakers according to those dates.
You should expect work on the following Views version which includes filtering by fields of related posts to be complete in a couple of months or so.
I followed your suggestion and added an appearance date field to the relationship. I added this field to the view filter but the result is still empty. What am I doing wrong?
Could I take a look at your site to check the set up myself?
I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes.
So, it seems there has been a misunderstanding between the developers and supporters about what is currently possible.
Specifically, you cannot filter posts by anything other than its own fields or taxonomies (which is how WP_Query works).
I mistakenly understood that the one exception was that it was possible to filter posts in a M2M relationship by the relationship fields (which are stored on an intermediate post type), but this, too, is something for which support is going to be added in the next Views dev cycle, which is about to commence.
Then it will be possible to filter by fields of related posts directly or by the relationship fields, but in the meantime it is not possible.
Sorry for leading you to think using the relationship fields was one way to achieve that now.
Sorry, no, this feature will be added in the next Views development cycle which is just beginning, but development of this (and other features in this cycle) and testing could take up to a couple of months.
"The feature of filtering one type of post by fields of another type of post is not yet supported, but is the main feature that will be added in the next Views development cycle, starting soon." Nigel