Hello, thank you for contact us. I will try to do my best to help you.
The date fields are stored as Timestamp in the database, this is an integer number like 1520848854. So, this is not a kind of filter that you can easily create with Toolset, but you can add some custom code that will help you to filter the view with the desired parameter passed as an argument in the shortcode. You can use this code and paste it into your functions.php file:
/**
* Convert the day parameter to Timestamp for Events view
*/
function convert_day_to_timestamp( $query_args, $view_settings, $view_id ) {
global $WP_Views;
$index = 0;
if( $view_id == 7 ) {
$view_shortcode_attributes = $WP_Views->view_shortcode_attributes;
$day = $view_shortcode_attributes[0]['day'];
$day_splitted = explode( '/', $day );
$start_time = mktime( 0, 0, 0, $day_splitted[1], $day_splitted[0], $day_splitted[2] );
$end_time = mktime( 23, 59, 59, $day_splitted[1], $day_splitted[0], $day_splitted[2]);
if( isset( $query_args[ 'meta_query' ] ) ) {
$index = count( $query_args[ 'meta_query' ] ) + 1;
}
$query_args[ 'meta_query' ][ $index ] = array (
array (
'key' => 'wpcf-end-date',
'value' => $end_time,
'type' => 'NUMERIC',
'compare' => '<='
),
array (
'key' => 'wpcf-start-date',
'value' => $start_time,
'type' => 'NUMERIC',
'compare' => '>='
),
'relation' => 'AND'
);
}
return $query_args;
}
add_filter( 'wpv_filter_query', 'convert_day_to_timestamp', 99, 3 );
You might need to change the following data:
- In the 8th line, you would need to change the number 7 to your View ID, you can find that, going to your view, and checking the URL, after the parameter view_id.
- In the 19th and 25th line, under the option 'key', you would need to change the key name to your custom field name. This is the prefix 'wpcf' and your custom field slug.
Please let me know if this solves the issue or if you need further details.
Have a good day.