Skip Navigation

[Resolved] View that filters posts by field from one to many relationship

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

Last updated by alexanderv-5 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1159719

I am trying to:
So, I'm trying to create a view that has filters (like a dropdown or a date picker) for certain custom fields. These Fields are not part of the custom post itself. They are in fact fields from the parent custom post type, fused together by a one-to-many relationship. When I try to filter by these custom fields of the parent custom post type, it does show nothing. The view shows the custom posts until I activate any kind of filter on the page it is displayed. After that, it does not find any items.

I tried to filter by other fields from the child post, that works fine.

Is what I try to achieve part of the system? Or should I try to do this another way?

#1159920

Hi, it's actually not possible to filter a View of post type A directly by custom fields in post type B, regardless of post relationship, in the current system. It's on our roadmap, but it's currently not available. It would require a significant amount of custom code to add custom search filters for fields in two different related post types.

Instead, one way you can accomplish something similar now is to create a filtered View of the parent post type and nest a View of related child posts. This approach will let you filter the results by parent post fields, but not by child post fields. There are also some limitations with pagination and post counts, which may be inconsistent when Views are nested. If that's okay, here's how it would work:
- Create a View of the child post type and add a Query Filter that filters by post relationship, where the parent post is the current post in the loop.
- Insert a link to the post in the loop.
- Create a View of the parent post type and add your custom field filters (parent fields only).
- Insert the child post View in the loop.
- Show the parent post View on the site.

Let me know if you have questions about this approach.

#1160615

Thank you for the suggestion. I made it a little bit different then you wrote but it was a great help.

In the end, I used a nesting of views as you wrote. But switched it up a bit to fit some other issues I could solve this way.

So I consider it resolved, still, I hope that someday you may add the filter by relationship of two different post types. But I had a look at your suggestion list for new features and I think you have other more pressing matters to put in first.

Thank you anyway and have a good day.