[Resolved] Custom search shows all results before query is entered

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.

This topic contains 2 replies, has 2 voices.

Last updated by chrisD-14 9 months, 3 weeks ago.

Assigned support staff: Waqar.

Author
Posts
#1263177

I have a custom search at hidden link

Before any search query has been entered, the search results show all products. I don't want anything to show up until a search query is entered. How can I achieve that?

#1264193

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Chris,

Thanks for asking! I'd be happy to help.

To make sure no results are shown from the view until a search term has been used, you can use conditional display block ( ref: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/ ) to check the value of the "wpv_post_search" URL parameter, through the "wpv-search-term" shortcode ( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-214940 ).

You'll note that when a search term is used in the view, it is appended in the URL parameter "wpv_post_search".

To get its value following shortcode can be used:


[wpv-search-term param="wpv_post_search"]

This can be combined in a conditional block like this:


[wpv-conditional if="( '[wpv-search-term param="wpv_post_search"]' ne '' )"]
A search term exists
[/wpv-conditional]

Likewise, this same conditional block can be used in the view's "Loop Editor" section, to wrap everything within the shortcodes "[wpv-layout-start]" and "[wpv-layout-end]".

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1264323

My issue is resolved now. Thank you!