Skip Navigation

[Résolu] filter a view by excluding post who have a relationship

This support ticket is created Il y a 5 années et 5 mois. 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/Karachi (GMT+05:00)

This topic contains 1 réponse, has 2 voix.

Last updated by Waqar Il y a 5 années et 5 mois.

Assisted by: Waqar.

Auteur
Publications
#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

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

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

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