I am trying to: Have a default date filter applied, which is shown. However The first load of the form does not honor the default filters.
Link to a page where the issue can be seen: hidden link
I expected to see: I do not expect to see listings with a date older than today.
Instead, I got: Items prior to the date selected listed.
I created a partial fix by adding:
jQuery(document).ready(function($) {
jQuery("select[name^='wpv-wpcf-training-scope'] option[value='Public']").attr("selected","selected").trigger("change");
});
However this code also runs when the page is refreshed which is incorrect. I only want it to run when the seach has not been run...
Hi,
Thank you for contacting us and I'd be happy to assist.
To suggest the best way to achieve this, I'll need to see exactly how this view's search filters are set up in the admin area.
Can you please share temporary admin login details, in reply to this message?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
regards,
Waqar
Hi,
Thank you for sharing the access details.
The "Course Schedule" page on your development website seems to be set up differently than the one at the staging website for which you shared access details.
However, if your goal is to apply the event date filter by default, to show only events starting from today, you can remove that custom script and instead use "wpv_filter_query" hook:
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )
add_filter( 'wpv_filter_query', 'default_date_filter_fn', 1000 , 3 );
function default_date_filter_fn( $query_args, $view_settings ) {
if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 1234) ) {
if(empty($query_args['meta_query']))
{
$date = new DateTime(date('l jS F Y'));
$date->setTime(0,0,0);
$query_args['meta_query'][0]['key'] = 'wpcf-event-date';
$query_args['meta_query'][0]['value'] = $date->getTimestamp();
$query_args['meta_query'][0]['type'] = 'NUMERIC';
$query_args['meta_query'][0]['compare'] = '>=';
$query_args['meta_query']['relation'] = 'AND';
}
}
return $query_args;
}
Note: Please replace '1234' with your actual View's ID.
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 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
This was awesome and sorted it right out! Perfecto.