Skip Navigation

[Resolved] WordPress Archive Page for Custom Post Type – Only display posts after searching

This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.

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: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by jabienL 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2563393

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.

#2563657

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 '' ))

#2564001

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.

#2564513

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?

#2564945

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?

#2565021

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

#2565445

My issue is resolved now. Thank you!