I found this post:
https://toolset.com/forums/topic/how-to-require-user-to-select-at-least-one-parameter-in-custom-search/
that seems to offer a solution for what I want to do: hide all search results until/unless a taxonomy value is chosen (on a page where filter and results are on same page).
My page with the filter and results is
hidden link
The URL of my View is (note view ID):
hidden link
I have this in my filter editor for the View:
[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group col-sm-4">
<label>[wpml-string context="wpv-views"]Areas[/wpml-string]</label>
[wpv-control-post-taxonomy taxonomy="ccb_core_group_area" type="select" url_param="wpv-ccb_core_group_area"]
</div>
<div class="form-group col-sm-4">
<label>[wpml-string context="wpv-views"]Days[/wpml-string]</label>
[wpv-control-post-taxonomy taxonomy="ccb_core_group_day" type="select" url_param="wpv-ccb_core_group_day"]
</div>
<div class="form-group col-sm-4">
<label>[wpml-string context="wpv-views"]Times[/wpml-string]</label>
[wpv-control-post-taxonomy taxonomy="ccb_core_group_time" type="select" url_param="wpv-ccb_core_group_time"]
</div>
<div class="form-group col-sm-4">
<label>[wpml-string context="wpv-views"]Types[/wpml-string]</label>
[wpv-control-post-taxonomy taxonomy="ccb_core_group_type" type="select" url_param="wpv-ccb_core_group_type"]
</div>
[/wpv-filter-controls]
[wpv-filter-end]
And I have this in my functions.php:
// Toolset: Hides Group Finder search results until a search field is selected by user
add_filter( 'wpv_filter_query', 'drop_empty_search_query', 10, 3 );
function drop_empty_search_query( $query_args, $view_settings, $view_id ) {
$ids = array(10243);
if (in_array($view_id, $ids)){
if (
// taxonomy filter needs to check for not '0' as well as not empty
( isset($_GET['wpv-ccb_core_group_area']) && $_GET['wpv-ccb_core_group_area'] != '0' )
||
// taxonomy filter needs to check for not '0' as well as not empty
( isset($_GET['wpv-ccb_core_group_day']) && $_GET['wpv-ccb_core_group_day'] != '0' )
||
// taxonomy filter needs to check for not '0' as well as not empty
( isset($_GET['wpv-ccb_core_group_time']) && $_GET['wpv-ccb_core_group_time'] != '0' )
||
// taxonomy filter needs to check for not '0' as well as not empty
( isset($_GET['wpv-ccb_core_group_type']) && $_GET['wpv-ccb_core_group_type'] != '0' )
) {
} else {
$query_args['post__in'] = array(0);
}
}
return $query_args;
}
But it does not work. The search fields no longer display the dropdown choices. Since I am adapting code from another post and am not a programmer I probably got something wrong but I dont see it.
Thank you for your help
It appears that you have the option "Only show available inputs" selected for your View in the custom search Advanced Options, which is incompatible with that code. This alternate approach works better when you want to combine "show only available inputs" with empty results until an option is selected:
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(10243);
if (in_array($view_id, $ids)){
if (
// taxonomy filter needs to check for not '0' as well as not empty
( isset($_GET['wpv-ccb_core_group_area']) && $_GET['wpv-ccb_core_group_area'] != '0' )
||
// taxonomy filter needs to check for not '0' as well as not empty
( isset($_GET['wpv-ccb_core_group_day']) && $_GET['wpv-ccb_core_group_day'] != '0' )
||
// taxonomy filter needs to check for not '0' as well as not empty
( isset($_GET['wpv-ccb_core_group_time']) && $_GET['wpv-ccb_core_group_time'] != '0' )
||
// taxonomy filter needs to check for not '0' as well as not empty
( isset($_GET['wpv-ccb_core_group_type']) && $_GET['wpv-ccb_core_group_type'] != '0' )
||
// initial load fix for "only show available inputs", this input does not exist
( isset($_GET['wpv_update_check']) )
) {
} else {
$query->posts = array();
$query->found_posts = 0;
$query->post_count = 0;
}
}
return $query;
}
Let me know if this does not work as expected.
Yes it now works as desired. I never would have figured that out on my own. Thank you Christian.