Issue with Post Loop Meta Query by custom datetime field if a field is conditionally disabled

Hi,

I have an issue / question

I need to filter a Query Loop by a Meta Query, which has two conditions based on the dates FROM and TO.

I have followed above’s tutorial to filter loops by date. I have two tabs:

  • current and upcoming events

  • past events

With this tutorial, it’s quite easy to achieve a desired result IF there are only single day events. The issue is if there are both single and multiday events.

In order for the event to appear under PAST EVENT both FROM and TO dates have to be LESSER than current WP time.

If it’s a multiday event, thus both dates are filled, it works correctly. However, if there is a single day event, it’s not being displayed at all, as a TO field is conditionally disabled (hide if empty) and there is nothing to compare against.

So somewhere in the logic/query, there should be information passed “Compare to a TO field if exists, otherwise compare only to FROM field”

image

Same issue with current/upcoming events tab.

How can I make it working?

Thanks