Problem: I have a custom search View with several filters. I would like to hide all the results in the View until at least one filter has been applied.
Solution: You can use the following custom code snippet to hide the results until some filter has been applied:
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){ $target_views = array( 123,456 ); // Comma-separated list of View IDs if ( in_array( $view_id, $target_views ) ) { // if there is a search term set if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) { $query_results->posts = array(); $query_results->post_count = 0; $query_results->found_posts = 0; } } return $query_results; } add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );
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 |
---|---|---|---|---|---|---|
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)
This topic contains 5 replies, has 3 voices.
Last updated by 4 years, 12 months ago.
Assisted by: Christian Cox.