Home › Toolset Professional Support › [Resolved] Hide default search result in view
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 |
---|---|---|---|---|---|---|
9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
This topic contains 8 replies, has 3 voices.
Last updated by johnC-6 3 years, 2 months ago.
Assisted by: Jamal.
On this page: hidden link, I have a search view. There is an initial search result showing before anyone makes a search - "HHG Capital Corporation Prices $50 Million Initial Public Offering". I don't want any results showing until someone actually searches for something. How do I accomplish this?
Thanks in advance for your help.
John
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Are you using the legacy editor for Views or the new block editor?
The principle is the same in either case. When a page with a View initially loads it doesn't have any search URL parameters. Once you submit a search parameters are added according to what you are searching/filtering by, but one which is always added is wpv_view_count.
So to not show any results initially you wrap the output section of the View inside a conditional (shortcode, or block), where the condition is whether the wpv_view_count parameter is something other than an empty string.
For a shortcode it would look like:
[wpv-conditional if = "( '[wpv-search-term param='wpv_view_count']' ne '' )"] ... loop output... [/wpv-conditional]
With Blocks the principle is the same but uses a Conditional block.
Hi Nigel,
Thanks for your help with this.
Unfortunately, I'm not following you. I'm using the legacy Views editor and this is what I have in the Output Editor:
[wpv-filter-meta-html]
[wpv-layout-meta-html]
When I copy and paste your code so it looks like this:
[wpv-conditional if = "( '[wpv-search-term param='wpv_view_count']' ne '' )"]
[wpv-filter-meta-html]
[wpv-layout-meta-html]
[/wpv-conditional]
The search box goes away on the front end. What am I doing wrong?
John
Hello John,
Can you try this instead:
[wpv-filter-meta-html] [wpv-conditional if = "( '[wpv-search-term param='wpv_view_count']' ne '' )"] [wpv-layout-meta-html] [/wpv-conditional]
If this does not help, allow me temporary access to your website and I'll check it further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Hello John,
I went with a different approach: Using custom code to programmatically skip the search for post if no search term was provided. Something like this https://toolset.com/forums/topic/how-to-make-default-results-blank-for-parametric-search/#post-347797
But, It is still not working as I would expect. I am still working on it and I'll get back to you as soon as I figure it out.
All the best,
Jamal
Actually, the custom code that I used works for the view when AJAX is not enabled. When AJAX is enabled the view does not get updated. Check this screenshot hidden link
I tried the view on a separate page to exclude any compatibility conflict with Elementor and the issue is still reproduced.
I am keen to think that another component is contributing to this issue. I would like to switch theme and disable some plugins during my testing. Can I do it on this server without impacting some other users?
Otherwise, can I take a copy of the website and work on it locally? This will also be useful if I needed to ask for assistance from our 2nd Tier team.
Hi Jamal,
I have cloned the site to a new URL and you can do any testing here: hidden link. Your login info is the same.
Thanks for all your help.
John
It turns out that the results are wrapped around a condition on the number of posts. The first load will produce 0 results and therefor the results section of the view is never displayed on the first load. This was done in the "Output Editor" section of the view. Check this screenshot hidden link
[wpv-filter-meta-html] [wpv-conditional if = "( '[wpv-search-term param='wpv_view_count']' ne '' )"] [wpv-layout-meta-html] [/wpv-conditional]
After removing the condition the view worked as expected:
[wpv-filter-meta-html] [wpv-layout-meta-html]
I added the view to the Elementor page, and it worked as expected. Check it here hidden link
Please update the production site from your side, and let me know if you have any further questions.
My issue is resolved now. Thank you so much for your help, Jamal! Much appreciated!