Hello,
I'm trying to set up an event website where visitors can pick a date and view every events available at this date.
I have no issue to set an event date and then search for that exact date, but is there any way to search between 2 dates (start and end) ?
Example with 2 events :
- Event 1 (one time event) : start date 15/05/2018 / end date 15/05/2018 (or no end date)
- Event 2 (6 days event) : start date 12/05/2018 / end date 18/05/2018
Now if I pick the date 15/05/2018 in my search, i want both events to show.
If i pick 17/05/2018, i only want Event 2.
Is this possible via Toolset ?
Thanks !
Yes, below are the steps to add a Custom Frontend Search by a Date Field, where you filter between 2 dates.
1. Create a View and query the post type where you use the Date Field (probably, "events", in your case)
2. Click on the "New Filter" button in the "Search and Pagination" section of the View, where you choose the Date Custom Field.
3. In the "Display Options" that appear as a pop-up, choose to "Using this comparison" > between.
4. Insert the ShortCode
This will create a Front-end Filter where the user can choose a minimum and maximum date from a date picker and submitting that search will show only posts with dates saved between the values set in the search.
Here you can read more about Date Queries themselves:
https://toolset.com/documentation/user-guides/date-filters/
https://toolset.com/documentation/user-guides/filtering-views-query-by-date/
Related to the issue you mention, let me reply below.
Example with 2 events :
- Event 1 (one time event) : start date 15/05/2018 / end date 15/05/2018 (or no end date)
- Event 2 (6 days event) : start date 12/05/2018 / end date 18/05/2018
Now if I pick the date 15/05/2018 in my search, i want both events to show.
If i pick 17/05/2018, i only want Event 2.
- If you pick the date 15/05/2018, then this is either a minimum or maximum date in a search as I show it above.
What is it in your case?
You need to set both dates in the search, to get a result of "between" two dates.
Searching by one specific date in a "range" of dates stored between multiple Date fields of the same post is possible, but you need to match the exact date in this case.
Thank you Beda.
If i understand correctly : if i want to search for a date in a range, i need to specify each date in that range ?
In that case set a single custom field 'date', make it able to be multiple and set each date ?
In my example above: if i want to be able to see Event 2 when i select 15/05, i need to set each date : 12/05, 13/05, 14/05, 15/05, 16/05, 17/05, 18/05
Well yes, if you want to be able to pick out ONE event by ONE date but the event may have been longer than the single day, then yes, there is no other way as storing and addressing this as a single field or a repeating instance of a field, although I disrecommend to use repeating fields just for ease.
I think you need a Custom Filter that allows to set 2 dates:
- start and end
Then when you submit the filter will return posts with ONE single date within that date range.
There is no need for repeating fields to find that one post.
Of course, you probably have a Field "Start Date" and "End Date", so you can easily just create 2 Custom Date Filters both filtering a range of those Date Fields.
Yes, the user will need to input practically 4 dates, in this case.
But it will return the expected results
Sadly i really need users to select a single date so i'll go with the repeating field solution.
It would be great if this is possible in the future. 😉
Thanks for your help Beda.
Have a nice day.