Thank you very much for making the time for this issue. I really appreciate it!
Yes, I think your developer is correct. I can confirm that when I using the following two shortcodes together, the issue occurs:
[wpv-form-view name="class-search" target_id="self"]
[wpv-view name="class-search" view_display="layout"]
and when using the following single shortcode, the issue does NOT occur:
[wpv-view name="class-search"]
Settings chosen when generating the two separate shortcodes attached.
The handling of the distance filter is different than all of the other filters, and it's not possible to check whether a distance search is being used with the wpv_filter_query_post_process filter being used in my previous code sample.
So a different approach is needed. This time we can use the wpv_filter_query filter, which runs before the database is queried, and simply check whether the $_POST object contains anything, which it would if filters are applied, but otherwise would not, and if it is bork the query by adding an impossible condition.
So, you could try this:
/**
* No initial results
*
* Bork results unless a filter has been applied
* which implies $_POST object with search terms
*/
function tssupp_bork_results( $query_args, $view_settings, $view_id ){
$target_views = array( 92 ); // Edit to add IDs of Views to add this to
if ( in_array( $view_id, $target_views ) && empty( $_POST ) ) {
// No $_POST object on initial page load, so bork View query
$query_args['post__in'] = array( 0 );
}
return $query_args;
}
add_filter( 'wpv_filter_query', 'tssupp_bork_results', 101, 3 );
But note that in this case whatever is in the no-results-found section of your Loop Output will be shown, you'll have to decide how you want to handle that.
Thanks Nigel. Unfortunately, this seems to bork results initially as well as after a search, similar to the first solution.
(i.e. results are always empty, not just initially empty.)
Do you think that checking for the presence of the 'toolset_maps_distance_center' parameter might be an effective way to handle this? Might something like this work? Or is this not a good way, in your opinion, to handle it...
function tssupp_bork_results( $query_args, $view_settings, $view_id ){
$target_views = array( 22 ); // Edit to add IDs of Views to add this to
if ( in_array( $view_id, $target_views ) && !isset( $_GET['toolset_maps_distance_center'] ) ) {
// No toolset_maps_distance_center param present, so bork View query
$query_args['post__in'] = array( 0 );
}
return $query_args;
}
add_filter( 'wpv_filter_query', 'tssupp_bork_results', 101, 3 );
Thanks again for your help! Really appreciate it, especially as I'm becoming familiar with Toolset.