Search date filter start & end date
-
hi,
I would like that the filter search work with also End Date.
Your support told me to ctnact you to help me to have the filter work also for end date.Now it works just with start date.
I have to change some file?which one? whta i have to do?
add some & condition??thanks a lot
The page I need help with: [log in to see the link]
-
Hi @alocin-deu,
Thank you for providing all the information. For WP Event Manager query we will provide support here so i asked you to put your issue here.You need to add code similar to this
You can change your key _event_end_date/** * This code gets your posted field and modifies the event search query */ add_filter( 'event_manager_get_listings', 'filter_by_country_field_query_args', 10, 2 ); function filter_by_country_field_query_args( $query_args, $args ) { if ( isset( $_POST['form_data'] ) ) { parse_str( $_POST['form_data'], $form_data ); if ( ! empty( $form_data['search_datetimes'] ) ) { if($form_data['search_datetimes'][0]=='datetime_today') { $datetime=date('Y-m-d'); $date_search[] = array( 'key' => '_event_start_date', 'value' => $datetime, 'compare' => 'LIKE', ); } elseif($form_data['search_datetimes'][0]=='datetime_tomorrow') { $datetime=date('Y-m-d',strtotime("+1 day")); $date_search[] = array( 'key' => '_event_start_date', 'value' => $datetime, 'compare' => 'LIKE', ); } elseif($form_data['search_datetimes'][0]=='datetime_thisweek') { $year=date('Y'); $weekNumber=date('W'); $dates[0]= date('Y-m-d', strtotime($year.'W'.str_pad($weekNumber, 2, 0, STR_PAD_LEFT))); $dates[1] = date('Y-m-d', strtotime($year.'W'.str_pad($weekNumber, 2, 0, STR_PAD_LEFT).' +6 days')); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_thisweekend') { $saturday_date=date('Y-m-d', strtotime('this Saturday', time())); $sunday_date=date('Y-m-d', strtotime('this Saturday +1 day', time())); $dates[0]= $saturday_date; $dates[1]= $sunday_date; $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_thismonth') { $dates[0]= date('Y-m-d', strtotime('first day of this month', time())); $dates[1] = date('Y-m-d', strtotime('last day of this month', time())); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_thisyear') { $dates[0]= date('Y-m-d', strtotime('first day of january', time())); $dates[1] = date('Y-m-d', strtotime('last day of december', time())); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_nextweek') { $year=date('Y'); $weekNumber=date('W')+1; $dates[0]= date('Y-m-d', strtotime($year.'W'.str_pad($weekNumber, 2, 0, STR_PAD_LEFT))); $dates[1] = date('Y-m-d', strtotime($year.'W'.str_pad($weekNumber, 2, 0, STR_PAD_LEFT).' +6 days')); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_nextweekend') { $next_saturday_date=date('Y-m-d', strtotime('next Saturday', time())); $next_sunday_date=date('Y-m-d', strtotime('next Saturday +1 day', time())); $dates[0]= $next_saturday_date; $dates[1]= $next_sunday_date; $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_nextmonth') { $dates[0]= date('Y-m-d', strtotime('first day of next month', time())); $dates[1] = date('Y-m-d', strtotime('last day of next month', time())); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_nextyear') { $year=date('Y')+1; $dates[0]= date('Y-m-d', strtotime('first day of January ' . $year, time())); $dates[1] = date('Y-m-d', strtotime('last day of december '. $year, time())); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } $query_args['meta_query'][] = $date_search; } } return $query_args; }
hi, thansk for the fast answer.
wher ei have to insert this code?
regards
NicolaHi @alocin-deu,
You need to add this code your theme’s function.php file and also make sure you have changed the key on above code to _event_end_date as per your requirement.Thank you.
hi,
i change _event_start_date for _event_end_date
in tomorrow and today option, now none show me the event. It uspposed to show one event that strt today and finish tomorrow.
Her emy text that i insert in function.php
/** * This code gets your posted field and modifies the event search query */ add_filter( 'event_manager_get_listings', 'filter_by_country_field_query_args', 10, 2 ); function filter_by_country_field_query_args( $query_args, $args ) { if ( isset( $_POST['form_data'] ) ) { parse_str( $_POST['form_data'], $form_data ); if ( ! empty( $form_data['search_datetimes'] ) ) { if($form_data['search_datetimes'][0]=='datetime_today') { $datetime=date('Y-m-d'); $date_search[] = array( 'key' => '_event_end_date', 'value' => $datetime, 'compare' => 'LIKE', ); } elseif($form_data['search_datetimes'][0]=='datetime_tomorrow') { $datetime=date('Y-m-d',strtotime("+1 day")); $date_search[] = array( 'key' => '_event_end_date', 'value' => $datetime, 'compare' => 'LIKE', ); } elseif($form_data['search_datetimes'][0]=='datetime_thisweek') { $year=date('Y'); $weekNumber=date('W'); $dates[0]= date('Y-m-d', strtotime($year.'W'.str_pad($weekNumber, 2, 0, STR_PAD_LEFT))); $dates[1] = date('Y-m-d', strtotime($year.'W'.str_pad($weekNumber, 2, 0, STR_PAD_LEFT).' +6 days')); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_thisweekend') { $saturday_date=date('Y-m-d', strtotime('this Saturday', time())); $sunday_date=date('Y-m-d', strtotime('this Saturday +1 day', time())); $dates[0]= $saturday_date; $dates[1]= $sunday_date; $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_thismonth') { $dates[0]= date('Y-m-d', strtotime('first day of this month', time())); $dates[1] = date('Y-m-d', strtotime('last day of this month', time())); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_thisyear') { $dates[0]= date('Y-m-d', strtotime('first day of january', time())); $dates[1] = date('Y-m-d', strtotime('last day of december', time())); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_nextweek') { $year=date('Y'); $weekNumber=date('W')+1; $dates[0]= date('Y-m-d', strtotime($year.'W'.str_pad($weekNumber, 2, 0, STR_PAD_LEFT))); $dates[1] = date('Y-m-d', strtotime($year.'W'.str_pad($weekNumber, 2, 0, STR_PAD_LEFT).' +6 days')); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_nextweekend') { $next_saturday_date=date('Y-m-d', strtotime('next Saturday', time())); $next_sunday_date=date('Y-m-d', strtotime('next Saturday +1 day', time())); $dates[0]= $next_saturday_date; $dates[1]= $next_sunday_date; $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_nextmonth') { $dates[0]= date('Y-m-d', strtotime('first day of next month', time())); $dates[1] = date('Y-m-d', strtotime('last day of next month', time())); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } elseif($form_data['search_datetimes'][0]=='datetime_nextyear') { $year=date('Y')+1; $dates[0]= date('Y-m-d', strtotime('first day of January ' . $year, time())); $dates[1] = date('Y-m-d', strtotime('last day of december '. $year, time())); $date_search[] = array( 'key' => '_event_start_date', 'value' => $dates, 'compare' => 'BETWEEN', 'type' => 'date' ); } $query_args['meta_query'][] = $date_search; } } return $query_args; }
-
This reply was modified 6 years, 5 months ago by
alocin-deu.
YOU ROCK !
i have added in wp-event-manager-function and work !!!
i just change the end date of today and tomorrow.
In my functions.php of the theme does not work :/
SO now is working Good !
thannks a lot
maybe i wil come with other 2 or 3 question ??
Hi @alocin-deu
If you add those changes in your theme’s function file it will work. You might be missing something. If you are changing plugin file you will be lost you changes after updating the plugin.
Yes, sure you can create new threads.
Thank you ??Hi,
I have created a event for today 21-9-18 until 23-9-18
If i filter today: it Does nto show up
If i filter tomorrow: it does not show up
If i filter this weekend: it does not show up
If i filter this week: It showupSo i think that change start_date for End_date now just cechk on the end date..so it does not work for intermediate or start date…
Is it possible to fix it or tell me how to solve?
thanksHi @alocin-deu,
You can do the condition like date
$date_search[] = array( 'key' => '_event_end_date', 'value' => array('2018-9-21','2018-9-23'), 'compare' => 'BETWEEN', 'type' => 'date' );
On above example i have just assigned static date you can change to your dynamic date and also add to your theme side filter as i have provided in above example.
Also apply same for _event_start_date so it will check starting date of event if is in between your date.
I hope it will solve you issue.-
This reply was modified 6 years, 5 months ago by
Hitesh Makvana.
hi, any extra suggestion? I stil did not get it.
Thanks
Hi @alocin-deu,
In WordPress query it is not working order by key as per i have tested from my end. If you can achieve with something else it would be awesome.
Due to some restriction of wordpress query it is not possible to get post by meta key.
Thank you
-
This reply was modified 6 years, 5 months ago by
- The topic ‘Search date filter start & end date’ is closed to new replies.