Forums › Forums › Search & Filter Pro › Date ranges with Search & Filter Pro and Events Manager
- This topic has 12 replies, 2 voices, and was last updated 4 years, 4 months ago by Trevor.
-
Anonymous(Private) September 12, 2019 at 4:15 pm #220901
Hi,
I’m developing an events listing here:
http://bollandlowe.net/dev/watford/visit/whats-on/
It uses Events Manager, and Search and Filter Pro to filter the listing. The category filtering and search is working fine, but I’m having a problem with date ranges.
I saw your other posts about the incompatibility between how Events Manager saves dates and how S&F works with them, and wrote this hook:
// Convert Events Manager dates yyyy-mm-dd to yyyymmdd and save to an ACF field, for Search & Filter Pro to use function save_event_meta( $post_id ){ if (get_post_type($post_id) == 'event'): $filter_event_start_date = date("Ymd", strtotime(get_post_meta($post_id, '_event_start_date', true))); $filter_event_end_date = date("Ymd", strtotime(get_post_meta($post_id, '_event_end_date', true))); update_field( 'filter_event_start_date', $filter_event_start_date , $post_id ); update_field( 'filter_event_end_date', $filter_event_end_date , $post_id ); endif; } add_action('acf/save_post', 'save_event_meta', 20); // run before ACF saves the $_POST['fields'] data
This converts the start and end dates from yyyy-mm-dd to yyyymmdd and saves them to fields. Numerical sorting based on this start date field works.
However, when I try to do a date range filter it doesn’t return any results. I’m at a bit of a loss, and was wondering if it’s because the querystring the datepicker creates is in a different format?
Any suggestions would be appreciated.
Thanks!
-
AuthorPosts