Jump to content

Selector returns odd results


Ferdi Derksen
 Share

Recommended Posts

Hi folks,

First of all - I'm not sure this is a explainable result - when so please explain (working with PW for only a few weeks now)

My website has a lot of events with a start- and enddate. I'm looking for a complete selector which will return the events happening between today (2015-11-06) and a week from now (2015-11-13).

I'm searching trough a lot of pages which have the following dates (testcase) ;

Title        |   Startdate       |   Enddate

---------------------------------------------

Event A  |   2015-09-21   |  2015-09-22

Event B  |   2015-09-21   |  2015-11-10

Event C  |   2015-09-21   |  2015-11-30

Event D  |   2015-11-07   |  2015-11-08

Event E  |   2015-11-07   |  2015-11-19

Event F  |   2015-11-18   |  2015-11-19

My expectations are events A and F not to show as a result (they have ended before today or starting after a week from now).

Given the dates my selectortest is the following;

template=event,enddate>=2015-11-06,enddate<=2015-11-13|startdate<=2015-11-13

... which results in only Event B and D

Simply switching the startdate and enddate did the trick;

template=event,enddate>=2015-11-06,startdate<=2015-11-13|enddate<=2015-11-13

... which results in events B, C, D and E

My question, why??

Link to comment
Share on other sites

You can use "|" to OR fields, or OR values, but not expressions. Your selector is translating to something you didn't intend. I think the selector you might be attempting is instead this: 

template=event, enddate>=2015-11-06, enddate|startdate<=2015-11-13

Or you could use OR-groups:

template=event, enddate>=2015-11-06, (enddate<=2015-11-13), (startdate<=2015-11-13)

Either of the above selectors says:

  • The template must be event.
  • AND The enddate must be greater than or equal to 2015-11-05.
  • ​AND (The enddate must be less than or equal to 2015-11-13 OR the start date must less than or equal to 2015-11-13). 
  • Like 5
Link to comment
Share on other sites

enddate<=2015-11-13|startdate<=2015-11-13

the OR operator "|" evaluates the first part and follows to the second only if the first is false. In this case the start day is never evaluated because it cannot possibly be true if the first is false. The start has to be earlier then the end.

PS: True, I didn't even think that you are using OR between expression. Ryan to the rescue already ;)

  • Like 3
Link to comment
Share on other sites

While ryan's code does certainly work you should be aware that this code wouldn't find events, that are longer than the mentioned "5 days from now" but still currently active. Such events could start before today and end after more than 5 days. To catch those as well you'd need another OR option like you can see in this topic: https://processwire.com/talk/topic/10682-help-with-date-range-selector/

  • Like 4
Link to comment
Share on other sites

While ryan's code does certainly work you should be aware that this code wouldn't find events, that are longer than the mentioned "5 days from now" but still currently active. Such events could start before today and end after more than 5 days. To catch those as well you'd need another OR option like you can see in this topic: https://processwire.com/talk/topic/10682-help-with-date-range-selector/

Please correct me if I'm wrong, but isn't this the same as Event C ?

This event is also shown in the results.

FYI; the selectors from the other topic also show the same results (B,C,D and E).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...