Home › Toolset Professional Support › [Resolved] Custom code to hide view results until a filter is chosen, additional question.
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.
This topic contains 3 replies, has 2 voices.
Last updated by lesleeM 1 year, 6 months ago.
You guys previously got me a custom code snippet to hide the view results from display until a filter is chosen. That code snippet is here:
<?php /** * Snippet to force end user to select a filter option before results will appear on Ride Maps page. */ toolset_snippet_security_check() or die( 'Direct access is not allowed' ); // Put the code of your snippet below this comment. add_filter('wpv_filter_query', 'wpv_no_results_by_default', 99, 3); function wpv_no_results_by_default( $query_args, $view_settings, $view_id ) { if($view_id == 2059 ){ if( !isset($_GET['wpv_view_count'])) { $query_args['post__in'] = array(0); } } return $query_args; }
My question now is I want to apply this same functionality to another view. The ID for that view is 8012. I just wanted to see if I only have to add this ID to the line saying:
if($view_id == 2059 ){
If so, is the correct syntax for this as follows:
if($view_id == 2059, 8012 ){
Or do I need to do something else?
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi there
This is how you can adapt your code so that it applies to multiple Views (you can keep adding View IDs to the list):
add_filter('wpv_filter_query', 'wpv_no_results_by_default', 99, 3); function wpv_no_results_by_default( $query_args, $view_settings, $view_id ) { if( in_array( $view_id, array( 2059, 8012 ) ) ){ if( !isset($_GET['wpv_view_count'])) { $query_args['post__in'] = array(0); } } return $query_args; }
If the code solution is working well for you by all means continue with it, but you might like to know that you can also achieve the same without code: https://toolset.com/course-lesson/creating-a-custom-search/#hide-the-search-results-until-the-first-search
The array code worked perfectly. I just stuck with that. I didn't realize there was an easier way. Thanks for both solutions though.
My issue is resolved now. Thank you!