Skip Navigation

[Resolved] Empty initial search value

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

This topic contains 6 replies, has 2 voices.

Last updated by Joakim Blix Jaksland 6 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#592413

Would like my therapist search: hidden link to have an empty initial search page like this: hidden link Just without any value in the search field.

How can i accomplish this?

#592517

Nigel
Supporter

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

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

Hi Joakim

The simplest way to have no initial results on a custom search form is to split the form and the results onto separate pages, as described in section 4.1 of this page: https://toolset.com/documentation/user-guides/front-page-filters/

If you want the results on the same page then you will need to use the Views API to modify the query so that no results are displayed.

You can try the following code, which, if there is no wpv_post_search parameter in the URL as on the initial page load, will remove the View results.

You'll need to add that to your theme's functions.php file, or using a plugin such as Code Snippets. Be sure to edit the id of the View.

/**
 * Custom wpv_filter_query_post_process usage
 *
 * Don't show View results if there is no search term
 */
function custom_wpv_filter_query_post_process( $query_results, $view_settings, $view_id ){

	if ( 6 == $view_id ) { // Edit the id as required

		// if there is a search term set
		if ( !isset( $query_results->query['wpv_post_search'] ) ) {
			$query_results->posts = array();
			$query_results->post_count = 0;
		}
	}

	return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'custom_wpv_filter_query_post_process', 10, 3 );
#594218

Thank you mate! Worked like a charm.
One more issue, would it be possible to control the initial map search to at least show Norway: hidden link

#594357

Nigel
Supporter

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

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

If you go back to where you insert the map itself using the wpv-map-render shortcode and do so again using the Fields and Views button, in the dialog you will find under Map Zoom and Center you have the option "Set zoom center and center manually" where you can enter coordinates that are used when the map loads and there are no markers.

#594360

Tried this: [wpv-map-render map_id="map-1" map_width="100%" map_height="400px" general_center_lat="59.91386880" general_center_lon="10.75224540"]

hidden link

Cant get it to work, did i do anything wrong in hte shortcode?

#594509

Nigel
Supporter

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

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

Hi Joakim

I'm not sure why it hasn't worked on your site, but, having tried this out on a local test site myself, I think we need another solution.

The coordinates you use in those options will centre the map at the location (or should) but the map won't update position depending on the markers that are subsequently added according to the filters, and I doubt that is what you want.

So. Revert your wpv-map-render shortcode to how it was.

Now, add a marker directly after the wpv-map-render shortcode with a static location (coordinates, for example), meaning it does not occur inside the wpv-loop tags and is only added once.

If you now visit your map you should see when it initially loads the map is centred on these coordinates, even though you have no other markers showing.

Now, we don't want this marker when there are actual results to display.

So go back to this static marker shortcode you just inserted and wrap it in a conditional shortcode that checks to see whether a search term has been specified, so it should look something like this:

[wpv-conditional if="( '[wpv-search-term param="wpv_post_search"]' eq '' )"]
  [wpv-map-marker map_id="map-1" marker_id="marker-[wpv-post-id]" address="1 Wall Street, New York, NY, United States"][/wpv-map-marker]
[/wpv-conditional]
#595613

Worked perfectly!

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