Skip Navigation

[Resolved] No initial results for a custom search (no filter) with map

This support ticket is created 3 years, 6 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
- 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 3 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2431299
Search a Tag – XO, Jane Doe - xojanedoe.kbccloud.com.jpg
Edit Page “Search a Tag” ‹ XO, Jane Doe — WordPress' - xojanedoe.kbccloud.com.jpg

Hello, I have been trying to implement a search page on my development site that displays the results of one search box that queries a custom meta field 'luggage-tag-number' and then displays all matching results with map location pins and the resulting custom post type below.

The search and map are working fine, I just want to know if there is a way to initially display nothing underneath in the posts view until a tag has been searched. Currently all the custom posts 'submissions' are displayed before any tag number is entered into the search field.

I am attaching images of the front-end display and the block set in the edit page mode. Let me know if you need anything else. I have the site in maintenance mode while I'm completing it but I can open it up if needed.

Thanks so much for your help!
Kelly

#2431741

Hi Kelly,

Thank you for contacting us and I'd be happy to assist.

To achieve this, you'll need a custom function attached to the "wpv_filter_query" hook:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

For example:


add_filter( 'wpv_filter_query', 'hide_till_search_custom_func', 99 , 3 );
function hide_till_search_custom_func( $query_args, $view_settings ) {

	// skip if blocks edit screen
	if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
		return $query_args;
	}

	// comma-separated list of target view names
	$target_views = array('Test view name');

	// get current view's name
	$current_view_title = get_the_title($view_settings['view_id']);
	
	// process if the current view is one of the target views
	if ( ( isset($view_settings['view_id']) && in_array($current_view_title, $target_views)) ) {
		if( empty($query_args['meta_query']) ) {
			$query_args['post__in'] = array(0);
		}
	}
	return $query_args;
}

Note: please replace 'Test view name' with your actual view's name for which you'd like to hold the results, until search.

Tip: You can also add multiple target view names in a comma-separated list, like this:


$target_views = array('Test view name 1', 'Test view name 2', 'Test view name 3');

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

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

regards,
Waqar