Home › Toolset Professional Support › [Resolved] Only show search results AFTER user has performed a search
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
Tagged: Custom search, Views plugin
Related documentation:
This topic contains 19 replies, has 2 voices.
Last updated by Nigel 6 years, 8 months ago.
Assisted by: Nigel.
Hello!
I'm new to Toolset and I am trying to allow users to search for classes nearby. I've set up a Custom Search View and have that working. BUT what I can't figure out how to do is only show the results AFTER the user has performed a search. Right now, all the results are displaying when the page loads.
Is this possible?
Here is a link to the page: hidden link
Thanks!!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Lauren
Views custom searches work by applying filters to narrow down the results, so that the initial state includes all results.
There is a simple way to display no results initially, and that is to create two pages, one where you insert the search form only, and one where you insert the results (including the search form so that the filters can be modified).
So on your search page when you insert the View choose to insert the search form only, and then insert the same View on your "Search results" page, this time selecting the results.
That is the intended way to have no initial results.
It is possible to show no initial results when using only a single page, but it requires adding some PHP to your site.
If you would prefer that let me know and I will elaborate further.
Thank you so much for the quick reply!!!
I am comfortable with PHP and would interested in hearing about that option as well.
Thanks!!!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Lauren
Here's a generic function to not show results unless a filter of some kind (custom field, taxonomy, or text search) has been set, if you want to give it a try, adding it to your theme's functions.php file or using a plugin such as Code Snippets.
/** * No initial results * * Don't show View results until a filter has been applied * * Tests for custom field filters, taxonomy filters, or text searches */ function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){ $target_views = array( 226 ); // Edit to add IDs of Views to add this to if ( in_array( $view_id, $target_views ) ) { // if there is a search term set if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) { $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 );
Will this PHP solution only work if the "full page refresh" update setting is chosen? Or will it work for AJAX results too?
I'm just noticing that, WITHOUT either of the above solutions in place, the "full page refresh" option is behaving strangely - overwriting my location info after I enter it. Do I have a view setting wrong? It's all pretty default at this point. I'm using Toolset Maps, and pretty much followed the instructions here:
https://toolset.com/documentation/user-guides/display-on-google-maps/
and here:
https://toolset.com/documentation/user-guides/front-page-filters/
Here's my test page:
hidden link
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Lauren
The code in question is designed to not show any initial results when the page first loads.
It shouldn't then matter whether the View is updated via a page refresh or via ajax.
I went to your link and tried to enter a location but it was dropped immediately after selecting it. (See screenshot.)
I have noticed this before on other sites, but haven't been able to consistently reproduce it for the developers to look at the issue.
In your case, do you only see the problem when the View is set to update via a full page refresh?
Hi Nigel,
Yes, the same is happening for me, even with a different theme (see screenshot: hidden link).
It happens with both of the "Full page refresh" options (with and without "input values auto-updating").
It does NOT happen with either of the AJAX options.
Let me know what I can do to help troubleshoot this issue. Thanks!!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Lauren
Can I get credentials for your site from you?
I'm going to escalate this thread and add it to the other report, which we've only been able to reproduce intermittently, and my colleagues may want a copy of your site for testing.
I suspect we are in different timezones so it will save time if I ask for those now.
I'm marking your next reply as private.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Thanks Lauren
I have taken a copy of your site and passed it on to my colleague to investigate further.
I'll update you when I have something to report.
Thanks for your patience.
Thank you!!!
Any luck?
Hello, just following up again. Any luck? Were you able to reproduce the issue also? Is there anything else I can do to help get this resolved at this point? Let me know.
Thanks!!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Lauren
I raised this with at the developer meeting this morning and asked them to expedite it as quickly as possible.
It is a bit of an all-hands-on-deck week trying to get the next beta release of Types and Views with CRED and WPML support published, but the developer in question will try and make the time to investigate.
It affects your site and at least one other, but isn't generally replicable, and they need to confirm why so that it can be fixed.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Lauren
A quick update.
The developer debugging this issue is able to reproduce it, and thinks that it only happens when you insert the View filters and View results separately, rather than together.
Have you split the form and the results when inserting the View?