Skip Navigation

[Resolved] Show additional search parameters only if the original search was submitted

This support ticket is created 4 years, 11 months 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
- 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)

This topic contains 4 replies, has 2 voices.

Last updated by JasonW6419 4 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1517209
0C28595E-A5F9-4EB4-92EE-FF7C05A859FB_4_5005_c.jpeg
1446E362-C414-4ABC-ABEF-9995B283D481_4_5005_c.jpeg
Screen Shot 2020-02-19 at 2.12.07 PM.png

I am responding to a closed ticket. Sorry I wasn't able to respond before it was closed.

The link to the closed ticket is : https://toolset.com/forums/topic/display-the-same-search-results-from-a-view-with-2-different-search-forms/

Using your example provided, I'm still unclear about what field and value to use for the condition using the GUI. It seems you understand what we're trying to do, however, the example provided is a still confusing for some reason. For example, what do I put in place of "mine" and "this" in the example you provided.

The first screenshot is our front-end search form for Home page only. The second screenshot is our front-end search form for the search results page where we want to show the additional drop-downs only when the Home page search box is filled out and submitted. The third screenshot is our code for the view which includes the additional search drop-downs that we want on the search results page. So, we want the additional search drop-downs to display only on the search results page.

Thank you

#1518049

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You should create your search View which includes all of the filter controls in the Search and Pagination section.

Note how Types fields have a wpcf- prefix, so the shortcodes to add the country filter control has a field attribute of "wpcf-country". Whenever a search is submitted the filter values are passed by URL parameters, and by default these are the fields with a wpv- prefix, e.g. "wpv-wpcf-country".

In the case of the text search box the URL parameter is wpv_post_search.

So, we want to conditionally display the other filter controls only when the wpv_post_search is present (i.e. something has been searched for, and we will therefore be on the results page). We can use the wpv-search-term shortcode to check the values of URL parameters (see https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-search-term).

That means adding a conditional shortcode where we check that the wpv_post_search parameter is not an empty string.

Here's the entirety of the Search and Pagination section from my site, where I'm hiding a taxonomy filter control rather than your custom field filters, but it should be clear how this is set up:

[wpv-filter-start hide="false"]
[wpv-filter-controls]
[wpv-conditional if="( '[wpv-search-term param='wpv_post_search']' ne '' )"]
<div class="form-group">
	<label for="wpv-colour">[wpml-string context="wpv-views"]Colours[/wpml-string]</label>
	[wpv-control-post-taxonomy taxonomy="colour" type="select" url_param="wpv-colour"]
</div>
[/wpv-conditional]
<div class="form-group">
	[wpv-filter-search-box output="bootstrap"]
</div>
[wpv-filter-submit output="bootstrap"]
[/wpv-filter-controls]
[wpv-filter-end]
#1519657

Thank you so much,

I understand now what you are saying. That was my thought, though, that I was needing to use 'ne'. I just wasn't sure how to do it using the GUI. The code is now working for the purposes I'm using it. So, thank you.

However, there happens to be another issue that I've found after testing for proper function. When I use the search box on 'Home Page,' it redirects to a 'Search Results Page' that I created with Elementor and implemented using the View widget. The drop-downs are appearing on this 'Search Results Page' as needed.

The issue is when I click on a link on my "full site" nav bar at the top of this 'Search Results Page, ie. 'About Us' and then use the web browser's back button to return to the 'Search Results Page, the drop-downs disappear. Is there conditional logic that I can apply to correct this?

If I need to post this as a new topic, please let me know.

Thanks in advance!

#1520363

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

When you land on the search results page from the home page URL parameters with the search terms are added, and these are what the conditional shortcode checks for.

If users may navigate to the results page differently then another approach may be needed.

In the filter controls section the context for Views shortcodes is the page where the View is shown, so wpv-post-url will output the URL of the current page.

So you could update your conditional shortcode so that it compares the output of the wpv-post-url shortcode to the home page URL and only show the controls if these are not equal, i.e. we are not on the home page.

Now, you can output the home page URL, i.e. the site URL, with the wpv-bloginfo shortcode, but when I was just trying that it doesn't output the trailing '/' which the wpv-post-url shortcode does, so that the comparison will fail.

So I think you need to just specify the home page URL as a string for the text comparison rather than generate it.

To make sure you compare like with like, simply output the wpv-post-url shortcode in the filter control section of your View, check how it appears on the front end on the home page, and use the resulting string in the wpv-conditional shortcode.

#1521973

That worked, thank you.

Then ending code for reference is:

[wpv-conditional if="( '[wpv-post-url]' ne 'hidden link' )"]