I am trying to have date filter here : hidden link (last select of the first line)
I have copied (and modified) another similar tickets (https://toolset.com/forums/topic/date-custom-field-range-filter/) but I am not successful.
Here is the snippet (I just changed the view_id to 38883 and the name of the field to "wpcf-date-debut"
------------
<?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;
}
-----------
and here is the definition of the filter in toolset views :
[wpv-control-postmeta type="select" field="wpcf-date-debut" source="custom" values="1,2,3,4,5" display_values="Dans moins de 1 semaine,Dans moins de 1 mois,Dans moins de 3 mois,Dans moins de 6 mois,Dans moins de 1 an" default_label="Date" url_param="wpv-wpcf-date-debut"]
Thanks for your help! (as you can guess, I am not a PHP coder.....)