Skip Navigation

[Resolved] how filter view using event date field to display today event

This thread is resolved. Here is a description of the problem and solution.

Problem:
how filter view using event date field to display today event

Solution:
You can use view's filter hook "wpv_filter_query" to modify the query arguments as per your need.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/split-split-use-non-types-custom-fields-of-yith-tickets-plugin-for-search-filters-filter-view-using-event-date-field/#post-1164572

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 5 years, 4 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Last updated by umbertoZ 5 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1163762

Yes! This solved the main problem, they are there and now I can manage those fields.

I still have some issue.

I can display _start_date_picker filed by this shortcode:

[wpv-post-field name='_start_date_picker']

But it seems I cannot change the date format as I can do with a Toolset Date field. How can I manage it?

I also tested the date filter, I can set it up, I also set date_format to Y-m-d (the current data format of _start_date_picker), but the search result is "No items found". I also try setting the Query filter to "like", but it still doesn't get any result.

Any suggestion?

#1163764

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I would like to know how you want to filter the view results by date. Do you want to display all the results that are less than the selected date or you want to apply "equal to" the selected date?

#1163776

I would like to build a select like this:

hidden link

I'm inetrested in this options:
Any date
Today
This weekend
This week
Next week
This Month
Pick a date

So the "equal to" is ok for the Pisck a date (maybe I can also split the select and add the calendar icon with date picker outside), but then I'd like to create the other options too.

thanks

#1164572

Minesh
Supporter

Languages: English (English )

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

I've added following code to Toolset Settings "Custom Code" section:

add_filter('wpv_filter_query', 'func_filter_events_by_date', 10, 3);  
function func_filter_events_by_date($query_args, $view_settings, $view_id) {
  
  global $WP_Views;
  global $wpdb;
    
if($view_id == 675)  {
    
  $start = $_GET['wpv-_start_date_picker'];
  $end = $_GET['wpv-_start_date_picker']+(24*3600);
  
  $field_name = '_start_date_picker';  // replace your field name 
  
     $sql = "SELECT post_id FROM ".$wpdb->prefix."postmeta,".$wpdb->prefix."posts  
                WHERE (".$wpdb->prefix."postmeta.post_id = ".$wpdb->prefix."posts.ID)
                AND ((".$wpdb->prefix."postmeta.meta_key = '".$field_name."'
                AND CAST(UNIX_TIMESTAMP(".$wpdb->prefix."postmeta.meta_value) AS SIGNED)  BETWEEN '".$start."' AND '".$end."'))
                AND ".$wpdb->prefix."posts.post_type = '".$query_args['post_type'][0]."'
                AND ((".$wpdb->prefix."posts.post_status = 'publish' OR ".$wpdb->prefix."posts.post_status = 'private'))";
  
       
                  $res = $wpdb->get_col($sql);
  
        if(!empty($res)){
            $query_args['post__in'] = $res;
              
        }
     
 }
return $query_args;
}

I can see its filtering the correct results based on the selected date:
=> hidden link

#1164585

Thank you!! It work great.

Can you give me any hint how to build a select with this options:

Any date
Today
This weekend
This week
Next week
This Month

It should be like this example:

hidden link

thanks

#1164590

Minesh
Supporter

Languages: English (English )

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

Well - you need to add a dropdown select box within the "search and pagination" section which have the options you required. You need to calculate the time for your each option and based on the selected option you need to adjust your views query which I already wrote for you.

Thank you.

#1164673

I'm sorry, I'm not sure I know what I should do.

I made a try adding a new "between" filter for _start_date (I set the filter output to "display:none"), then I've created some shortcodes to display "today date", "tomorrow date" and "next 7 days" and finally I've added this select:

<select class="event-on-select" onchange="location = this.value;">
        <option value="?&any=selected" [wpv-search-term param="any"]>Any date</option>
        <option value="?wpv-start-min=[wpv-today]&wpv-start-max=[wpv-today]&today=selected" [wpv-search-term param="today"]>Today</option>
        <option value="?wpv-start-min=[wpv-tomorrow]&wpv-start-max=[wpv-tomorrow]&tomorrow=selected" [wpv-search-term param="tomorrow"]>Tomorrow</option>
        <option value="?wpv-start-min=[wpv-today]&wpv-start-max=[wpv-week]&week=selected" [wpv-search-term param="week"]>This week</option>
      </select>

It works, but it is not working fine with the rest of AJAX filters.

Can you help again to work with your php code?

thanks

#1164676

Minesh
Supporter

Languages: English (English )

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

Sorry to say this, this may be the thing which you do not like but I (we) need to work within the predefined support boundary.

This needs custom programming which is beyond the scope of our support policy. I already show you a way how to do this and shared the hints but we can not do custom programming for your custom requirements.

I hope I made my point clear and its simple to understand, If you need custom programming for your project, please feel free to contact our certified partners. They will be happy to help you with your any custom programming needs:
=> https://toolset.com/contractors/

Thank you for understanding.

#1164717

Don't worry, I understand it, you gave me a great help. Just one more question to understand if I'm on the right way.

Should I replicate your code, edit $start and $end variables to make the job?

I've another issue with the Map location filter. I want to add a distance filter, but it doesn't get the YITH non-Types field _direction_event, even if it is alredy managed by Types. How can I do it?

I know it's a different issue, but I would like you split again the topic, I'd like to follow with you because you already know the project and you already have full the access to it.

thanks

#1164725

Minesh
Supporter

Languages: English (English )

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

Should I replicate your code, edit $start and $end variables to make the job?
=> Yes, and if needed you need to modify the query but its totally depends on your requirement and how you pass the data.

I've another issue with the Map location filter. I want to add a distance filter, but it doesn't get the YITH non-Types field _direction_event, even if it is alredy managed by Types. How can I do it?
I know it's a different issue, but I would like you split again the topic, I'd like to follow with you because you already know the project and you already have full the access to it.
==> I understand and I respect your intention to work with me. I kindly urge you to create a new ticket and feel free to assign it to me. As I'm about to end the shift today. I will take care of your ticket tomorrow.

Thank you. Please feel free to close the ticket.

#1165063

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.