Hi,
The function below, which you helped me implement, shows empty results by default and works well.
However, when I click on submit with no search term in the form all the posts are displayed.
I would like this, simply not to happen. i.e. clicking submit on the empty form does nothing.
Can I add something to this function below to do this?
Any advice you can provide would be much appreciated.
BillD
Thank you for getting in touch.
The reason why the search now shows everything after the search button is pressed is because a search is actually perform even though your haven't selected a specific criteria.
Whenever a search is performed then the url parameter "wpv_view_count" is added to the URL. This is the safest parameter to check as it is always added when a search is performed.
Once this url is added then the function will pick this up and then allow the results to be displayed.
Hi Shane,
Thank you for your reply.
It works perfectly as it is, except when a search is done on an empty search form.
I would prefer it NOT to find everything and display hundreds of posts and pages when a user does an empty search.
Is it possible to redirect back to the same page or simply disable the search if a user performs a search with an empty search form?
Any advice would be much appreciated.
BillD
I was trying to add something to your function :
/*WP TOOLSET blank search results*/
add_filter( 'wpv_filter_query', 'show_empty_results_default_func', 10,2 );
function show_empty_results_default_func( $query_args, $setting ) {
if($setting['view_id'] == 40){
**************
to get a redirect to the page $target = '/no-results/';
by using something from this below - from a different wp searchform:
add_filter( 'wpv_view_count', 'no_query_redirect' );
function no_query_redirect( $query ) {
if ( empty( $query->query_vars['s'] ) ) {
$target = '/no-results/';
if ( isset( $_REQUEST['search_form'] ) && ('a' == $_REQUEST['search_form'] ) ) {
$target = '/no-results/';
}
wp_safe_redirect( $target );
exit();
}
return $query;
}
************
But I got lost.
Any ideas?
If not I'll get you access over the next few days.
BillD