Skip Navigation

[Resolved] Datepicker not filtering

This support ticket is created 3 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Luigi Bella 3 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1802155

Tell us what you are trying to do?
I would like to have datepicker to display the child posts with the appropriate custom field – date, which is stored as a timestamp.

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/views/date-filters/

Here's a screen-recording of my issue: hidden link

#1802739

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I checked the video you shared and I see when you selected the date, the view do not find any posts.

Can you please share problem URL where you added the date filter as well as access details that will allow me to review your current setup.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1804369

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link?

I've added the following view's filter to "Custom Code" section offered by Toolset with snippet name "Toolset Custom Code":
=> hidden link


add_filter( 'wpv_filter_query', 'func_filtre_dateincident', 10, 3 );
function func_filtre_dateincident( $query, $settings, $views_id ) {
       
    if($views_id == 251655){
       
     if(!empty($query['meta_query'])){ 
       foreach((array)$query['meta_query'] as $k=>$v):
            if(isset($v['key']) and $v['key']=='wpcf-dated'){
                   
                $values = explode(",",$v['value']);
                 
                if(!empty($values)){
                     
                    unset($query['meta_query'][$k]);
                      $dvalue[] = $values[0];
                      $dvalue[]  = $values[0] + 24 * 60 * 60;
                  
                        $query['meta_query'][$k]['key'] = 'wpcf-dated';
                        $query['meta_query'][$k]['type'] = 'NUMERIC';
                        $query['meta_query'][$k]['compare'] = 'between';
                        $query['meta_query'][$k]['value'] =  join(",",$dvalue);
                }
                   
                   
            }
        endforeach;
     }        
      
    return $query;
    }
}

Can you please confirm it works as expected.

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#1806477

Hi Minesh,

The datepicker does work. However, what changes will need to be made if the same issue occurs on another site with the same view? Just changing the views id number?

Thank you.

#1807905

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - you should change the view ID from:

   if($views_id == 251655){
  

To:

   if($views_id == 99999 ){
 

Where:
Change 99999 with your view ID.

#1809051

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.