Get_events based on time
WordPress Event Management, Calendars & Registration › Forums › General Question › Get_events based on time
This topic contains 11 replies, has 2 voices, and was last updated by Stephen Harris 10 years, 7 months ago.
-
AuthorPosts
-
July 28, 2014 at 8:07 am #11837
Hi,
I have been trying to show events starting from now to the end of the day but with time. So if an event starts at 9:05, it would hide at 9:06, but I just found out that event_start_after and etc.. work with date, not time. Is there some quick and easy way to use it on time, rather than using long and complicated $wpdb?
Thanks,
MarkMarek Zelezny
July 28, 2014 at 9:44 am #11838Hi Mark,
but I just found out that event_start_after and etc.. work with date, not time
That shouldn’t be the case. If you found some documentation saying that, could you point it out to me – it’s probably outdated. Time support for event queries was implemented a long time ago.
$events = eo_get_events( array( 'event_start_after' => 'now', 'event_end_before' => 'today', //Queries are inclusive! ) );
Should work. There was a bug with
eo_get_events()
and relative date/queries which was fixed in Event Organiser 2.8.0.Stephen Harris
July 28, 2014 at 10:06 am #11841I read on page http://codex.wp-event-organiser.com/function-eo_get_events.html this
event_end_after – default: null. Events that end after the given date. This argument, and those above expect dates in Y-m-d format or relative dates.
That “Y-m-d” format confused me probably then, but the problem is not fixed. I actually had it like this before.
I set an event for today from 10:55 to 10:55 / 11:00 (gmt+2), it is now 10:57 / 11:04 and the event is still shown. So I guess I am wrongly choosing timeframe.This is the code:
eo_get_events(array( 'posts_per_age' => 5, 'event_start_after' => 'now', 'event_end_before' => 'today', 'meta_key' => 'mz_hoditdolu', 'meta_value' => 'ne' ));
Marek Zelezny
July 28, 2014 at 10:14 am #11842I set an event for today from 10:55 to 10:55 / 11:00 (gmt+2), it is now 10:57 / 11:04
Sorry, that’s confused me. Just to clarify: the event starts at 10:55 and finishes at 11:00 (local time) and the event doesn’t appear at 10:57?
That would be expected, the current query is:
Show events that
- start after now (10:57)
- and end on or before today
If you’d like events that are running and at any point from now to the end of the day, try:
eo_get_events(array( 'event_end_after' => 'now', 'event_start_before' => 'today', ));
Stephen Harris
July 28, 2014 at 10:20 am #11843I shouldn’t have added that 11:00 time there. At first, I tried to set start time at 10:55 and end time 10:55. At 10:57 it was still shown. Then I tried 10:55 to 11:00 in case same start and end time would conflict but it was still there at 11:04.
eo_get_events(array( 'event_end_after' => 'now', 'event_start_before' => 'today', ));
I tried but it’s still there (event’s set time)
Marek Zelezny
July 28, 2014 at 10:33 am #11844Hmm… that’s odd,
Could you try adding this immediately before that query. It will kill the page and print the SQL statement.
add_action( 'posts_request', 'wp_die' );
What’s the SQL statement?
(One thing to note – just make sure your computer time agrees with your website. I mention this because when I’m testing/developing I’ll occasionally change the timezone in WordPress, forget about it and become convinced there’s a bug down the line when the events I’m expecting are not showing up 😉 )
Stephen Harris
July 28, 2014 at 10:39 am #11845I visited the timezone setting in WordPress so many times wondering if it’s okay but yes it is (GMT+2).
Here’s the statement
SELECT wp_posts.*, wp_eo_events.event_id, wp_eo_events.event_id AS occurrence_id, wp_eo_events.StartDate, wp_eo_events.StartTime, wp_eo_events.EndDate, wp_eo_events.FinishTime, wp_eo_events.event_occurrence FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) LEFT JOIN wp_eo_events ON wp_posts.id = wp_eo_events.post_id WHERE 1=1 AND wp_posts.post_type = ‘event’ AND ((wp_posts.post_status = ‘publish’)) AND ( (wp_postmeta.meta_key = ‘mz_hoditdolu’ AND CAST(wp_postmeta.meta_value AS CHAR) = ‘ne’) ) AND (wp_eo_events.StartDate > ‘2014-07-28’ OR (wp_eo_events.StartDate = ‘2014-07-28′ AND wp_eo_events.StartTime > ’10:34:42’)) AND wp_eo_events.EndDate <= ‘2014-07-28’ GROUP BY wp_eo_events.event_id ORDER BY wp_eo_events.StartDate ASC, wp_eo_events.StartTime ASC
Marek Zelezny
July 28, 2014 at 10:46 am #11846Ah, that will be why.
Could you select a city rather than an offset? The plug-in uses
DateTimeZone
which requires a city rather than offset, it does try to ‘guess’ a city from the given offset, but I’m not sure why it’s not working in this case.Can you confirm this by going to
.../wp-admin/edit.php?post_type=event&page=debug
and checking what the “Timezone” option is. It’ll probably be (incorrectly):Europe/London ( 2 / )
Hence the hour discrepancy in the SQL statement.
Stephen Harris
July 28, 2014 at 11:03 am #11847Hmm, you are right, there is London. How can I change the city because I don’t know what I am exactly supposed to do.
EDIT: Do you mean venue city?
Marek Zelezny
July 28, 2014 at 11:10 am #11848In Settings > General (WordPress’ general settings) you can select a timezone. Apart from the UTC offsets there are a list of cities, grouped by contintent you can select.
Stephen Harris
July 28, 2014 at 11:40 am #11849I see, I have never noticed there are also cities.
Now it’s working. Thanks!
Marek Zelezny
July 28, 2014 at 11:43 am #11850No worries. The ‘bug’ which led to Europe/London being selected is because London adopted the +2 UTC timezone during WW2. :/. Hence it’s listed as a city with a UTC+2 offset (as well as UTC+0/1).
After some research I’ve managed to improve it, but it’s always recommended to use cities over offsets.
Stephen Harris
-
AuthorPosts