Skip Navigation

[Resolved] Filter view by post without relationship

This support ticket is created 5 years, 8 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)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1233576

How can i set filter in view to display posts without relationship with the post where this view is shown?

Query filter section have only option to filter posts with relationship. In my case, i need to display post if don't have relationship.

#1233800

Hi there,

Thank you for contacting us and I'll be happy to assist.

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

1. 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 and please let me know if you need any further assistance around this.

regards,
Waqar