Home › Forums › Calendar Products › Events Calendar PRO › Events Passing Too Soon
- This topic has 12 replies, 2 voices, and was last updated 11 years, 4 months ago by
Brian.
-
AuthorPosts
-
December 4, 2014 at 10:10 am #907841
andrew82
ParticipantHi Geoff && || Any Other Super Handy Support Rep,
I’ve just upgraded to Events Calendar PRO and I’m looking for a wee bit of help with a implementation I engineered based on this thread (https://theeventscalendar.com/support/forums/topic/calling-event-listing-onto-homepage/).In the the end, the above code calls all my events onto the homepage, but doesn’t take into account events that have passed, so some further tweaks were necessary. I found filter_all_tribe_occurrences(); here somewhere here in the forums and that was just what I needed. There’s only one teeny problem left. Events seem to pass (so disappear from the homepage) about 2 hours before they should. So an event at 6pm, disappears from the homepage at 4pm. I would assume this is something about the Timezone used by the TimeDate(); but I tried modifying the code below a few ways, all without success. Can you help a brother out?
add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100); function filter_tribe_all_occurences ($wp_query) { if ( !is_admin() ) { $new_meta = array(); $today = new DateTime(); // Join with existing meta_query if(is_array($wp_query->meta_query)) $new_meta = $wp_query->meta_query; // Add new meta_query, select events ending from now forward $new_meta[] = array( 'key' => '_EventEndDate', 'type' => 'DATETIME', 'compare' => '>=', 'value' => $today->format('Y-m-d H:i:s') ); $wp_query->set( 'meta_query', $new_meta ); } return $wp_query; } ?> <?php // Calls Events from Events Calendar $posts_array = tribe_get_events( $full = false ); foreach ( $posts_array as $post ) : setup_postdata( $post ); ?> <div id="post-<?php the_ID() ?>" class="<?php tribe_events_event_classes() ?>"> <?php tribe_get_template_part( 'list/single', 'event' ) ?> </div><!-- .hentry .vevent --> <?php endforeach; ?>December 4, 2014 at 1:17 pm #908015Brian
MemberHi,
Thanks for using our plugins and looks like you are close.
Hard to say what the problem is, but what day and time does this return:
new DateTime();
Can you add 2 hours to that and does that resolve it? Have you tried that already?
Let me know.
Thanks
December 8, 2014 at 8:48 am #911863andrew82
ParticipantHi Brian,
Thanks for the tip. It seems like new DateTime(); produdes a time which is 5 hrs (not 2) ahead of our current timezone. I would have tried to echo that previous to posting first, but I could get echo $today; to work as DateTime has a specific format which needs to be called to echo as I’ve figured out in the PHP Manual. In this case instead of adding or subtracting time to even it out I used the date_default_timezone_set(‘America/New_York’); and the America/New_York timezone to set the timezone to EST here in the U.S. I called this function just before the new DateTime function in the code above. like this..if ( !is_admin() ) {
$new_meta = array();
date_default_timezone_set(‘America/New_York’);
$today = new DateTime();
echo $today->format(‘Y-m-d H:i:s’);And the time is currently being set at the right timezone (instead of UTC). So I think this should be good. Once I see the events ‘expire’ from the homepage at the right time this evening I’ll post to confirm everything is all good!
December 8, 2014 at 1:14 pm #912238Brian
MemberOk great, glad you are a step closer.
Let us know how it works out.
Thanks
January 8, 2015 at 12:07 pm #930553andrew82
ParticipantOk, So everything worked fine for a while, or as I thought. But it seems like there is still a big issue with this. The homepage event listing is now showing that the events start at their prescribed end time. So if the event runs from 6-7pm it’s showing on the homepage that it starts at 7pm. Some unhappy campers with the event attendees so far đŸ™‚ Furthermore Its seems as if only on my homepage is the new DateTime(); active. Therefore if you click on the event for further details, the event post itself shows that warning ‘This event has passed’ in blue at page top when it should not be passed. Here’s my custom call for events on the homepage template
add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100); function filter_tribe_all_occurences ($wp_query) { if ( !is_admin() ) { $new_meta = array(); date_default_timezone_set('America/New_York'); $today = new DateTime(); // echo $today->format('Y-m-d H:i:s'); // Join with existing meta_query if(is_array($wp_query->meta_query)) $new_meta = $wp_query->meta_query; // Add new meta_query, select events ending from now forward $new_meta[] = array( 'key' => '_EventEndDate', 'type' => 'DATETIME', 'compare' => '>=', 'value' => $today->format('Y-m-d H:i:s') ); $wp_query->set( 'meta_query', $new_meta ); } return $wp_query; } ?> <?php // Calls Events from Events Calendar $posts_array = tribe_get_events( $full = false ); foreach ( $posts_array as $post ) : setup_postdata( $post ); ?> <div id="post-<?php the_ID() ?>" class="<?php tribe_events_event_classes() ?>"> <?php tribe_get_template_part( 'list/single', 'event' ) ?> </div><!-- .hentry .vevent --> <?php endforeach; ?>January 8, 2015 at 12:44 pm #930566andrew82
ParticipantEither I love answering my own questions or I don’t give myself enough credit to sort it out myself. The issue with events showing at their end time, instead of start time (something folks at the studio didn’t like much) was due to
'key' => '_EventEndDate',in my code. Of course changing this to EventStartDate takes care of that problem wonderfully.The remaining issue is that the singular event listing is still showing itself passed so it’s labeled with a ‘This event has passed’ in blue above the event when it is still to take place. Obviously my New timeDate() is only active on the homepage. So the bigger question is why is Events Calendar Pro operating on UTC time when we are in EST North America? And if I can correct it on my homepage with a New timeDate() call, do I have to do it everywhere else?
A live link to the site: http://www.swandojo.com
January 8, 2015 at 1:26 pm #930585Brian
MemberHi,
Sorry for the issues you are having.
I took a look at your site and see on the home page is showing Zumba w/ Belinda with this date and time Jan 8th @ 6:00 pm – 7:00 pm
That is also what I see on the Single Event is that not correct? Which events are showing the times wrong on the the home page?
Single Event Message
Not sure why the This event has passed is showing. It would seem to me there is something going on with the timezones.The function that controls that text is called set_notices()
Found at the end of this template:
the-events-calendar\lib\template-classes\single-event.php
The function uses this function for the time:
time()And then this for the gmt_offset:
$gmt_offset = ( get_option( 'gmt_offset' ) >= '0' ) ? ' +' . get_option( 'gmt_offset' ) : " " . get_option( 'gmt_offset' );
$gmt_offset = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $gmt_offset );
Does the time() return the correct time for your site? and what about the gmt_offset?
Let me know and we can go from there.
Thanks
January 9, 2015 at 6:53 am #930853andrew82
ParticipantHi Brian, My previous post shows that I sorted out the issue with events showing their end time as their start time. It was the
'key' => '_EventEndDate',in my code above which needed to be changed to'key' => '_EventStartDate',The issue with the event’s showing to be passed, at the event level itself is still happening though and the time offset is 5 hours, which is the difference between EST in North America and GMT. Calling the date() function as in the single-event.php as below..
echo 'Now: '. date("F j, Y, g:i a") ."\n";gives me GMT time instead of my local timezone. I’ve added ‘-5’ as the value in the GMT offset of the set_notices() function in the single-event.php in the the-events-calendar/lib/template-classes folder. And it does not change the above output, so it’s still reading GMT time. I am using events calendar pro and I also have my own template for single-events in my theme in the ‘tribe-events’ folder.
Any idea how I can get things running on my local timezone?January 9, 2015 at 7:50 am #930881Brian
MemberGood to know about the Home Page. I misread and thought the times were showing wrong.
I checked around on my site and unable to reproduce the error and have GMT set to -5 by default as well.
There are 3 variables in that function so one or more is incorrect.
I created this function to check the variables:
https://gist.github.com/jesseeproductions/e6aead398e6ffab51a98
If you place that in the set_notices() function that should let us know if those times are correct.
Let me know what you find out.
Thanks
January 9, 2015 at 1:14 pm #931023andrew82
ParticipantHi Brian, Thanks alot for writing that up. I pasted that code into my set_notices() and got the following output
gmt offset: +0
event end time actual: 2015-01-09 19:30
event end time with offset (+5 from actual endtime): 1420831800 = 2015-01-09 19:30:00
current time GMT (+5 from east coast): 1420837612 = 2015-01-09 21:06:52I’ve put a screenshot here for you for further reference if you want to see it on the page.
My coding chops are not wicked great, but I believe there is still a problem.
January 9, 2015 at 2:31 pm #931040Brian
MemberOk so the gmt offset variable should be -5 for the east coast.
I have my Timezone setting in WordPress on this page:
Settings > General set to New York and get -5.
If I set it to London I get +0.
What setting do you have there?
January 9, 2015 at 3:29 pm #931065andrew82
ParticipantI had UTC Brian! I’ve been working with WordPress for 6 years or so and never had to set the date via the WP admin, and if I knew that was there I would been the first to check it. Thanks for all your help!
It seems like everything works fine, I’ll watch an event expire in the next hour and make sure I get the notice ‘this event has passed’.Thanks for your help and determination!
January 12, 2015 at 7:49 am #931521Brian
MemberI am glad to see you were able to figure it out. Next time you will know where to look! đŸ™‚
I am going to go ahead and close this ticket. If you have a similar issue or another in the future, please do not hesitate to create a new ticket.
Thanks!
-
AuthorPosts
- The topic ‘Events Passing Too Soon’ is closed to new replies.
