[Resolved] How to add begins and ends date filters for when there is any overlap in dates
This thread is resolved. Here is a description of the problem and solution.
Problem:
Client has start date and end date custom fields. In a custom search View they have added filters for the begin and end dates, but would like posts to be included in the results if any part of its dates overlap with the filter start and end dates.
Solution:
The trick is to compare the start date from the filter with the end date of the post, and the end date from the filter with the start date of the post.
Insert filters for the start and end dates. In the Query Filter section (you may need to use the Screen Options tab at the very top of the page to expose it) edit the filters to swap the URL parameters used by the two filters, and to make it so the the start AND end filters must be true.
I'm not sure I understand why that would be the case.
Can you display the debug info for this View?
Go to Toolset > Settings > Front-end Content and enable debug mode for Views.
Then visit the page where you have the View inserted.
The debug window will pop-up, but we want to see the query when the date filters have been set, so choose your dates and then reload the page.
Now it will display some information about the View, including the query arguments used.
Can you see what the wpv_filter_query arguments are (the arguments the query is submitted with) and also the actual resulting SQL database query, and paste them below?
I don't think it is a bug. It is finding the right settings. When there is a product available from 1 april until 31 oct. So I want people to be able to find this when:
-they search in a range from 1 jan 2018 until 1 jan 2019 (then the product will be in between the dates)
-they search from 31 march until 7 april
-they search from 28 oct until 5 nov
So sorry. Didn't read it and probably jumped to conclusions! I am graving for some rest :-).
I set this now but when I search from 5 april to 26 april it is not showing me anything. Why? I don't get it anymore. The tour is available from 1 april tot 31 oct it should be there shouldn't it?
OK, that's not quite the scenario you initially described, but I understand now what you are aiming for, which is that if any part of the dates overlap it is considered a match.
So, let's see.
What you need is to edit the conditions so that you compare the start date from the filter with the end date of the post AND the end date of the filter with the start date of the post.
You need
Begintijd <= wpv_wpcf_eindtijd
AND
Eindtijd >= wpv_wpcf_begintijd