I have an entry which shows related events, based on the entry category, at the bottom. These events all have a start date and an end date - the end date is required, if the event is only one day, eventEndDate should be set to the same date as eventStartDate.
I have created a query with parameters to pull in related events, but only want events that are in the future. I need the query to take into account both start and end date - for example, the start date may have passed, but if the end date is still in the future this event can be shown. If both have passed, it should not show.
My difficulty is having the query treat these two parameters as 'OR' rather than 'AND'. I can't find docs on the correct syntax to achieve this. I have shown below the query as I currently have it. It establishes the current entry category; sets the parameters for section, checking for the start date being in the future and limits to 3 events, and then uses these parameters to pull in any related events that are not the current one.
{% set category = entry.eventCategory %}
{% set relatedParms = { section : 'schoolsAndEducators', eventStartDate: "> " ~ (now|atom), limit: '3' } %}
{% set relatedEvents = craft.entries(relatedParms).id('not ' ~ entry.id).orderBy('RAND()').all() %}
I'm not sure if it is possible, but I need to modify that 'relatedParams' query to also take eventEndDate into account. The below does not work, as it treats it like an 'AND' statement and only pulls in events for which both dates have passed:
{% set relatedParms = { section : 'schoolsAndEducators', eventStartDate: "> " ~ (now|atom), eventEndDate: "> " ~ (now|atom), limit: '3' } %}
I have checked similar questions here but either they aren't the same situation or I can't figure how to adjust the code for my particular requirements.
startDate
in the query? Unless I've read your question incorrectly, If the start + end dates are the same in some instances, you're really going to be querying just theendDate
anyway. Also since you're really only looking for dates that aren't "expired" yet, the start date doesn't really matter. The only time you'd want to query the start date would be if you wanted to look for events in a small sliver of time (eg "beginning next week but before next month) but that doesn't seem to be the case here?