Skip Navigation

[Resolved] default value for query

This support ticket is created 4 years 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 4 years ago.

Assisted by: Waqar.

Author
Posts
#1927341
Toolset 2-1-2021.png

Tell us what you are trying to do?
I have this query on a view
-----
Select items with field: email is a string equal to URL_PARAM(wpv-wpcf-email)
-----
and I am attempting to define a default email address in case the parameter is not provided (see file)

Is there any documentation that you are following? YES
https://toolset.com/forums/topic/display-default-value-in-a-parametric-search-filter/#post-376020
thanks for your help, your support has been fantastic!

#1927405

Hi,

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

If your goal is to apply the email field filter with a default email address when it is not provided by the user search, you can use the filter "wpv_filter_query".
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )

For example:


add_filter( 'wpv_filter_query', 'default_email_filter_fn', 1000 , 3 );
function default_email_filter_fn( $query_args, $view_settings ) {
	// if the target view
	if ( (!is_admin() && isset($view_settings['view_id'])) && ($view_settings['view_id'] == 12345) ) {
		// if meta query filter is not applied, apply it with default email
		if( empty($query_args['meta_query']) ) {
			$query_args['meta_query'][0] = array(
				'key' => 'wpcf-email',
				'value' => 'test@test.com',
				'type' => 'CHAR',
				'compare' => '='
			);
		}
	}

	return $query_args;
}

Note: Please replace "12345" with your actual view's ID and the "test@test.com" with your default email.

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.

regards,
Waqar