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!
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