Get_events based on time

This topic contains 11 replies, has 2 voices, and was last updated by  Stephen Harris 9 years, 9 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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,
    Mark

    Marek Zelezny
    #11838

    Hi 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
    #11841

    I 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
    #11842

    I 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
    #11843

    I 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
    #11844

    Hmm… 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
    #11845

    I 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
    #11846

    Ah, 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
    #11847

    Hmm, 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
    #11848

    In 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
    #11849

    I see, I have never noticed there are also cities.

    Now it’s working. Thanks!

    Marek Zelezny
    #11850

    No 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
Viewing 12 posts - 1 through 12 (of 12 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.