Skip Navigation

[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.

Relevant Documentation:
https://toolset.com/documentation/user-guides/filtering-views-query-by-date/

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

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 7 replies, has 2 voices.

Last updated by marcov-3 7 years ago.

Assisted by: Nigel.

Author
Posts
#599832

Hi,

I posted this ticket. https://toolset.com/forums/topic/show-view-results-that-are-overlapping-start-and-endtime/
I am seeing some problems with our setting now. When you select 1 jan 2018 till 31 dec 2018 it will not show any post. What can I do to prevent this?

Search is on the homepage. It is not a live site yet.

Cheers

#599919

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Marco

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?

#599924
Schermafbeelding 2017-12-18 om 15.38.33.png

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

Si this is what I want to be able to

Cheers

#600113

And of course when the search 1 april until 7 april or 1 june until 1 septemeber etc. Do you understand what I mean?

Cheers

#600129

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Marco

You have Begintijd less than or equal to the filter and it should be greater than.

You have Endtijd greater than or equal to the filter and it should be less than.

That's what I suggested in the original post and which logically makes sense to me.

#600131
Schermafbeelding 2017-12-19 om 10.20.02.png
Schermafbeelding 2017-12-19 om 10.19.53.png

Hi Nigel,

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?

#600148

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

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

That should do the trick.

#600150

Hi Nigel,
Explaining is the hard part. Sorry for the unclearness.

It is working like a charm!

Thanks