Skip Navigation

[Resolved] Split: Default date in datepicker – default date filter for custom search

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 2 replies, has 2 voices.

Last updated by Minesh 8 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2686440

Second issue: In the frontend the timestamp is pre-selected. However, you must click Submit for this filter to be activated (or changing a filter when using ajax refresh on filter change). So we think, there should be an automatic refresh on frontend, when a default date is set. Please see my screenshot for reference. Best regards, Christian.

#2686441

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

You can use the Toolset Views/Blocks "wpv_filter_query" hook to filter the view results on fly.
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

You can add the following code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

add_filter( 'wpv_filter_query', 'func_filterby_default_today_date', 99, 3 );
function func_filterby_default_today_date( $query, $view_settings, $view_id ) {
 
  if( !is_admin() and $view_id == 99999) {
    /// default today time
    $selected_start = strtotime('0:00:00');
     $date_field_slug = 'session-date';

    if(!isset($query['meta_query']) ) {
     
        $args = array(
      'relation' => 'AND',
       array(
        'key' => 'wpcf-'.$date_field_slug ,
        'value' => $selected_start,
        'compare' => '>=',
        'type' => 'numeric'
      )
    );
    // add these arguments to your meta query
    $query['meta_query'] = isset($query['meta_query']) ? $query['meta_query'] : [];
    $query['meta_query'][] = $args;
        
   }
      
  
  }
  
  return $query;
}

- Replace 99999 with your original view ID
- Replace $date_field_slug value with your original custom date field slug

#2686593

Minesh
Supporter

Languages: English (English )

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

If your issue is resolved - you're welcome to mark resolve this ticket.