Posted: October 10, 2017 at 3:05 pm
I need to find events that start on a specific set of dates. Fragment of my code:
The generated SQL:
It just replaced all dates with the current date and time; any idea what I’m doing wrong?
|
|
(btw: a post preview or edit would be nice; the markup syntax is quite unclear to me – looks like markdown, but apparently it isn’t) |
|
Hi Sara, You can’t pass strings like above for the date, you need to pass a date object. There are some details here: http://developer.eventespresso.com/important-changes-to-ee-datetime-system-coming-to-ee/ In the above example, you’re
To confirm, are you looking to pull events with either of those exact start dates/time? |
|
Sorry, missed your reaction. Yes, I’d like to find all other events in the same venue overlapping on one or more dates of this event. |
|
Just to clarify what I mean. You’re using ‘IN’ so the above is only going to pull events with a start date of So do you want IN or BETWEEN? BETWEEN will pull all events with a start date between 2017-11-10 09:00:00 and 2017-07-03 08:00:00. Either way the above should work it’s just not clear which events you want to pull from the database. |
|
Here’s the thing: we have a six-day event, but customers can also register for the first day only. We have created two separate events in EE: one for the full six days, and one for the first day only (called ‘try-out day’). So the answer is: IN, not BETWEEN. |
|
Also, the two events do not necessarily have the same startdates, e.g. it should also be possible to create an event for days 3-4 only. Registrants for that event should appear on the list of attendees of the full 6 day event too. The only restriction is that it is always a subset of the main event. |
|
Actually I did find a solution based on your suggestion, although it is a little cumbersome (find all datetimes of the main event, find all events on these datetimes in the same venue, find all registrations of these events etc…). |
|
You may be able to squeeze that into a single query with a few or more table JOINS. You may prefer to (or even need to) do more of a direct query using the wpdb class and its methods because it may get more cumbersome with the built in models. At the very least the query will include the esp_event_venue table (relationship between event and venue), |
|
That was my plan B. Thanks for all the suggestions and the (as usual) swift response. |
|
The support post ‘Search events by specific start dates generates wrong SQL’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.