I am trying to: Use a function to stop search results from loading only on initial page load, not after sending blank queries through the text search.
Link to a page where the issue can be seen: hidden link
I expected to see: The search results do not show on initial page load. However, if a text search is entered, and then "cleared" by deleting the text search input box and submitting a text search of "", the results still don't load. I would like the results to load if an empty string is sent through the text search.
I am AJAXing in results and keeping the search parameters in the URL.
Instead, I got: If an empty string is submitted after initial page load, results do not load. I would like them to.
I am using the following function I found from a separate support ticket:
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
$target_views = array( 2832 ); // Edit to add IDs of Views to add this to
if ( in_array( $view_id, $target_views ) ) {
// is there a filter set?
if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) && !isset( $_SERVER['QUERY_STRING'] ) ) {
$query_results->posts = array();
$query_results->post_count = 0;
}
}
return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );
I added the !isset($_SERVER['QUERY_STRING']), but it didn't work.
Hello. Thank you for contacting the Toolset support.
Well - when you say text search will you input "" (Quotes) to search field or just click directly on search button having text search field empty?
In order to fix your issue, I need access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
I am still curious to know if there is a way to display all search results when nothing is entered into the search box after initial page load.
However, I ended up simply writing a javascript function that simply reloads the home page if the search box is empty -- effectively "resetting" the search. This doesn't quite achieve what I initially wanted, but it provides a user-friendly workaround.
If you have a solution, let me know - I'd probably implement it instead of the JS solution I have in place now.