Skip Navigation

[Resolved] many-to-many relationship : filter and the sorting

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to filter by fields of related posts?

Solution:
It is currently not possible, but is a feature that will become possible after the update to Types 3.0 and related Toolset plugin updates. It won't make the cut for the initial release, but is one of the first features that will be added thereafter.

This support ticket is created 6 years, 9 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.

Our next available supporter will start replying to tickets in about 0.14 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 6 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#617313

Hello,

I am new user of Toolset. I'm currently creating a database that basically has exactly the same problem as described here:

https://toolset.com/documentation/user-guides/many-to-many-post-relationship/

But what I miss with the example:

All events where bands appear are to be displayed in a view sorted by event date. Events older than today should not be shown anymore.

In a "1-n" relationship, no problem in a view. In a "many-to-many" relationship I can not get the filter and the sorting.

Best regards

Michael

#617386

Nigel
Supporter

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

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

Hi Michael

The current implementation of post relationships typically involves using a View that queries the intermediate post type to be able to display related content.

The problem then becomes that you can only filter (or sort) something by properties of the thing itself, i.e. you can sort or filter intermediate posts by fields of intermediate posts, not by fields of the parent posts.

I have used this analogy before to explain, which may make sense:

With a playground of children you might tell all the children wearing hats to stand on the left, simple enough.

Your request sounds more like telling all the children whose parents have a combined income over €100k to stand on the left. But you don't know what the income of the parents of the children is, and guessing from the labels on their coats doesn't count.

This would work if the children came to school with a badge showing their parents' income.

In terms of querying the database that would be akin to custom table joins with SQL, and goes beyond the querying possible natively with WP_Query (and, therefore, Views).

Now, post relationships are being significantly overhauled (new betas will be published imminently) and will make this possible, to filter and sort by fields of the parents.

There will be new documentation published to describe the changes, too.

I suggest you wait a day or two and then familiarise yourself with what is involved with the new system and adopt that for any new project.