Hi,
I am trying to set up a search on an archive page for a custom post type. I only want the posts to show up after they search for them. I tried using this code ( ( '[wpv-search-term param='wpv_view_count']' ne '' ) ) which worked but it has a small bug. If you empty the search box and submit then it shows all of the posts. Is there a way to make the empty search box return empty results?
Thanks in advance.
Hello,
I assume we are talking about search box created with shortcode [wpv-filter-search-box output="bootstrap"].
If it is, it will pass URL parameter "wpv_post_search" to the search result page, so you can change the codes you mentioned above as below:
( ( '[wpv-search-term param='wpv_view_count']' ne '' ) AND ( '[wpv-search-term param='wpv_post_search']' ne '' ))
Thanks for the assistance but that didn't work.
What is working:
1. The page loads with empty search results.
2. If you search for something, it loads the correct posts.
What is NOT working:
1. After you search for something, if you erase the search term and then search, it shows all posts instead of an empty results page. Here is the parameter that shows up in the URL if you do that: ?wpv_view_count=513100
Any ideas?
Thanks again.
I have tried it in a fresh WP installation + the latest version of Toolset plugins it works fine, see below sandbox site:
Login URL: hidden link
1) WordPress Archive for custom post type:
hidden link
In section "Output Editor", setup the wpv-conditional shortcode as below:
[wpv-conditional if="( ( '[wpv-search-term param='wpv_view_count']' ne '' ) AND ( '[wpv-search-term param='wpv_post_search']' ne '' ) )"]
[wpv-layout-meta-html]
[/wpv-conditional]
2) Test it in frontend:
hidden link
click "Submit" button, I don't see any result, is this what you need?
Yeah, I can see that it works in the demo but it doesn't work on my site. I am using the block editor and don't have access to the Output Editor (as far as I can tell) which is what you used on the demo site. Is it possible to get this to work with the block editor as I have a lot of other formatted content on that archive page?
You can follow our document to wrap view's loop into the conditional block:
https://toolset.com/course-lesson/creating-a-custom-search/#hide-the-search-results-until-the-first-search
I have tried it in above sandbox website, it works fine too:
WordPress Archive with blocks editor:
hidden link
See the result in frontend:
hidden link
My issue is resolved now. Thank you!