I have a PHP code snippet that I have copied here in the FAQ (and I also opened a ticket for it 7 months ago).
This code is used to create a Date filter (less than a week, less than a month, etc.). It worked for a time and now it seems to create a bug .... (to help you understand I can tell you that the host uses PHP 8.1)
You can experience it here : hidden link (choose something in the date dropdown menu)
Here is the code :
<?php
/**
* Ce code permet d'interpréter le filtre par date pour le calendrier interactif
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
add_filter( 'wpv_filter_query', 'func_custom_filter_query', 10, 3);
function func_custom_filter_query( $view_args, $view_settings, $view_id ){
if ( 38883 == $view_id ) {
if ( (isset($view_args['meta_query'])) && (!empty($view_args['meta_query'])) ) {
$target_field = "wpcf-date-debut"; // change this field slug to your field slug
foreach ($view_args['meta_query'] as $key => $value):
if ($value['key'] == $target_field){
$option = $value['value'];
$start = time();
if($option==1){
$end = strtotime("+7 day",$start);
}else if($option==2){
$end = strtotime("+1 month",$start);
}else if($option==3){
$end = strtotime("+3 month",$start);
}else if($option==4){
$end = strtotime("+6 month",$start);
}else if($option==5){
$end = strtotime("+12 month",$start);
}else if($option==0){
unset($view_args['meta_query'][$key]);
return $view_args;
}
$filer_index = $key;
}
endforeach;
if ( isset($filer_index) ) {
$view_args['meta_query'][$filer_index] = array('key' => $target_field,
'value' => array($start, $end),
'type' => 'NUMERIC',
'compare' => 'BETWEEN' );
}
}
}
return $view_args;
}
thank you !!