Skip Navigation

[Resolved] Display posts with a null M2M relationship

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

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 4 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1324767

I have a post type called Students and a post type called Routes, with a many-to-many relationship between them.

I have created a view that lists the students and the routes that they have been assigned to. I can visually identify those without a route assignment, but it would be useful to be able to filter these records to ONLY show those posts where no relationship between the post types exists.

#1324793
exclude.JPG

Hello,

I assume you are going to get all "Students" posts without related Routes post setting.

As you see, there isn't such kind of built-in feature within Views plugin, but there is a workaround:
1) Since you can get those "Students" post IDs with related Routes post setting, you can pass them to below post view as shortcode attribute "ids"
2) Setup a post view:
- Query Students posts
- Filter by:
Exclude posts with IDs set by the View shortcode attribute "ids"
See screenshot: exclude.JPG

More help:
https://toolset.com/documentation/user-guides/filtering-views-query-by-post-id/

#1327651

Hi Luo

I'm sorry but that doesn't make any sense to me.

To show the students assigned to routes I have a 'child' view that pulls the route assignment and then I show that view within the loop of the parent view.

I'm assuming that I would duplicate these views and then modify one of them along the lines of what you have suggested?

#1327663

Yes, you can duplicate these views and then modify the outputs: output only the post IDs in comma separator format, for example: 123, 456, 789

Then pass the result as View shortcode attribute "ids" as I mentioned above.

See similar thread here:
https://toolset.com/forums/topic/the-paginations-are-not-appearing/#post-1319885

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.