Skip Navigation

[Resolved] Partly show search results before actual search

This support ticket is created 5 years, 1 month 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+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by Bob 5 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1219646

Bob

I have view in which one can search people and show results on a map, with a listing beneath that. Initially I would like to only show the results on the map and not show the listing beneath that. After committing a search on distance and place I would like to show those (limited) results on the map including the listing beneath that.
I know I can show the search results on a separate page, but that doesn't show the initial map.

hidden link

How would I go about this?

#1219717

Nigel
Supporter

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

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

Hi there

A View with filters initially shows all results until you apply filters to narrow down the results.

If you are using a View to generate both a map with markers and a list of posts then in your loop section you must be outputting both the marker and the fields that will appear in the list.

So your challenge is when the page first loads to show the markers but not the list (even though the same posts are being iterated over in the loop), and then when a search is made to show both.

So you don't need to do anything with the markers.

You would need to conditionally show the posts only when a search has been made.

You'll need to use wpv-conditional shortcodes for that, see: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

But what should you test?

Well, when you apply filters with a View, assuming your settings (at Toolset > Settings > Front-end Content) are set to "Enable history management setttings for AJAX custom search", then the URL will change to include certain URL parameters.

Here, for example, is what happened to the URL when I applied a distance search on my local test site:

<em><u>hidden link</u></em>

You can get the value of a URL parameter with the wpv-search-term shortcode (https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term), specifying which parameter using the 'param' attribute.

I haven't tested whether you can use a not-equals test for when a param has some unknown value (e.g. toolset_maps_distance_radius), but if needs be you could probably test for whether toolset_maps_distance_unit=km or somesuch.

Only display the list of posts when that is true.

Are you able to try that?

#1219743

Bob

Goody goody goody! That worked swell.

[wpv-conditional if="[wpv-search-term param='toolset_maps_distance_radius']"] --- ignore this content --- [/wpv-conditional]

I put that around the list items and the pagination and boom! 🙂

Thanks a bunch!

#1219800

Bob

So far so good, but I noticed that pressing the submit button without entering a place name will list all CPT's nonetheless. How would I avoid this? And while we're at it, how would I prevent a search being made solely on taxonomies (gastouder/nanny) without entering a place name?

#1219804

Bob

Found it! Edit the distance filter and set:

distance_center_required="yes" 

🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.