Skip Navigation

[Resuelto] How to make a view that only shows posts that are not related

This support ticket is created hace 5 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: 

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Luo Yang hace 5 años, 6 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#1244694

Tell us what you are trying to do?

I have a CPT called Bread and a CPT called Allergics.
I want to make a view with a filter through checkboxes. This view shows all the Bread posts.
The allergic Posts are shown with checkboxes. When I select pa. Nuts, now all the Breads which have nuts in them are shown.
I want it the other way around so by checking different boxes, the visitor can see which bread he or she can safely eat.
I guess I need a NOT statement instead of a OR statement.

Is there any documentation that you are following?

Been searching quiet some time in your documentation. Perhaps missed an article.

#1244917

Hello,

Thanks for the details, there isn't such kind of built-in feature within Views plugin:

I want it the other way around so by checking different boxes, the visitor can see which bread he or she can safely eat.

It needs custom codes, here are my suggestions:

1) When user submit the search form, use wpv_filter_query to trigger a PHP function,
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

2) In this PHP function, do these:
- get the post ID values of URL parameter "Allergics"

- use above values to get related "bread" post IDs
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts

- apply post IDs filter to query, exclude above specific "bread" post IDs
https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
post__not_in (array) - use post ids. Specify post NOT to retrieve. If this is used in the same query as post__in, it will be ignored