[Resolved] The Event Calendar – Today’s Event Not Showing

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.

This thread is resolved. Here is a description of the problem and solution.

Problem:

Using custom codes to filter view by custom field "_EventStartDate", I'd like the event to show until today at midnight, then drop off.

Solution:

It should be a timezone problem, see the solution here: https://toolset.com/forums/topic/the-event-calendar-todays-event-not-showing/#post-1138214

Relevant Documentation:

https://codex.wordpress.org/Function_Reference/current_time

This topic contains 8 replies, has 3 voices.

Last updated by rusty 1 week, 6 days ago.

Assigned support staff: Luo Yang.

Author
Posts
#1130708

I built a view to show the three latest events, including today's event on the home page.

Link to a page where the issue can be seen: Site Home Page

After implementing the workaround in #1117132 https://toolset.com/forums/topic/date-comparison-error-with-tribe-events-calendar-after-update/, the filtering is working ok, except that it doesn't show today's events. My current filter is: _EventStartDate is a DATE greater than or equal TODAY()

I've also tried:_EventStartDate is a DATE greater than or equal PAST_DAY(1), but it still won't show today's event.

#1131054

Beda
Supporter

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

Timezone: Europe/Zurich (GMT+01:00)

Try change DATE to NUMBER, that should solve this issue.
If not, then it is due to this, likely:
https://toolset.com/forums/topic/date-comparison-error-same-as-post-1116145/

If so, please let us know, since we would need to analyse this, and not simply close the ticket as done there, with the statement that it does "not work".
We do not do that usually @Toolset. We help or at least try to until the issue is either clear or solved.

Please let me know how above tests go, and if you use the Plugin (I cannot see it on your Debug info, hence I think after changing to NUMBER; the issue should be solved)

#1131234

Hi Beda,

I changed DATE to number, but that results in no output at all (No Items Found).

I've also changed the event dates ahead 1 day (works as expected - the event shows) and experimented with various combinations of DATE, number, TODAY, NOW, PAST_DAY(1), FUTURE_DAY(-1), etc. to no avail.

It seems that the problem lies with the interpretation of relative dates such as TODAY and NOW because even setting the filter in the view to _EventStartDate is a DATE greater than or equal THIS_MONTH() should show any event of this month, before or after the current day, but still only shows events in next month.

#1131769

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi,

Thanks for the details, I can login your website, please point out the problem page URL and view URL, where I can edit your PHP codes, I need to test and debug in a live website.

#1136947

Sorry for the delay. The issue exists on the front page. About 1/3 down you'll see the 3 most recent calendar events showing.

The view: hidden link
A demo event you can work with: hidden link

Right now (9:00am GMT -7) I am able to set an event for today that starts at 4:01pm and it shows correctly. However, in one minute, at 9:01am, the event drops off. Ideally, I'd like the events to stay visible until midnight of the day of the event, regardless of the start time of the event. For example, if I have an event today at 3pm, I'd like the event to show until today at midnight, then drop off.

Thank you very much for your assistance.

#1137344

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Thanks for the details, I assume we are talking about the custom PHP codes in your website:
hidden link

As you can see it is applying custom filter to field "_EventStartDate", so you don't need to setup filter on the same field in view UI.

I have done below modification in your website:
Edit the view "FP Events View", in section "Query Filter", remove the filter on "_EventStartDate", please test it again.

#1137615

Thank you Luo, unfortunately that didn't solve the issue. The events are still expiring 7 hours prior to the event start time. I experimented in the custom PHP code with the type (date, number, string) and operator (> and >=) with no luck, however, changing the operator to < does show events prior to today, but <= also does not show today's event. Curiously, using != returns only past events. Using just = as the operator returns no results at all, but I would expect it to show only today's event.

#1138002

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Thanks for the clarification, it should be a problem timezone problem, if I am right, your web server is using different timezone setting from your wordpress setting:
Dashboard->Settings-> General, option "Timezone"

In your case, you can modify the PHP codes from:
hidden link

...
      'value'   =>  date("Y-m-d H:i:s"),
...

To:

...
      'value'   =>  date("Y-m-d H:i:s", current_time( 'timestamp')),
...

More help:
hidden link
timestamp
The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

https://codex.wordpress.org/Function_Reference/current_time
Returns the blog's current local time in the specified format.

#1138214

That fixed it almost perfectly! I want the events to expire at midnight on the day of the event, not at their start time so building on what you wrote, I did the following:

I defined timestamp as a variable for midnight, instead of the current time:

$timestamp = strtotime('today midnight');

Then used that variable instead of 'timestamp':

'value'   =>  date("Y-m-d H:i:s", current_time($timestamp)),

I'll be testing it for a few days, but I do believe that it works exactly as it should now. Thank you!!