Problem: I have a custom search View with two control fields. I would like to require the User to select a value in both fields before any results are shown. As it is now, when the page loads all the results are shown. I would like to show no results.
Solution: @e have an API that is helpful for this situation: wpv_filter_query_post_process. This will allow you to intercept the search results and test the query. If either option is blank, or 0, show no results.
// custom filter that shows no search results if either filter is empty add_filter( 'wpv_filter_query_post_process', 'drop_empty_search_query_post_process', 10, 3 ); function drop_empty_search_query_post_process( $query, $view_settings, $view_id ) { $ids = array(12345); if (in_array($view_id, $ids)){ if ( // supplier type filter needs to check for not '0' as well as not empty ( isset($_GET['wpv-supplier-category']) && $_GET['wpv-supplier-category'] != '0' ) && // location filter needs to check for not '0' as well as not empty ( isset($_GET['wpv-area-served']) && $_GET['wpv-area-served'] != '0' ) ) { } else { $query->posts = array(); $query->found_posts = 0; $query->post_count = 0; } } return $query; }
Replace 12345 with the numeric ID of this View. You can customize the "No results found" message in the View's Loop Output editor panel.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Este tema contiene 4 respuestas, tiene 2 mensajes.
Última actualización por hace 6 años, 5 meses.
Asistido por: Christian Cox.