Skip Navigation

[Resolved] filter a view by excluding post who have a relationship

This support ticket is created 5 years, 11 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
- 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#1164001

I would like to filter a custom types post by posts who do not have a relationship with other specific post type
Is it possible?

#1164657

Hi Meirk,

Thanks for asking! I'd be happy to help.

To filter out specific posts which have a relationship with another post, you have a couple of options:

1. If you're showing your posts through a view, you can create a custom shortcode that gets the ID of the post and checks it for a relationship using "toolset_get_related_posts" ( https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts ).

If a relationship is found the shortcode can return 'true" and if not it can return "false".

Next, you can use this shortcode in a condition to show or hide content from that specific post:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

2. Another option is to use a secondary view to generate a list of IDs for all those posts which are in a relationship and then use those IDs in "post__not_in" array to be excluded from your primary view's output.
https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

I hope these suggestions will help.

regards,
Waqar