Viewing 8 replies - 1 through 8 (of 8 total)
  • There’s no way to do that out-of-the-box, it might be possible with some jQuery or another plugin.

    Thread Starter Menno1987

    (@menno1987)

    I’ve actually almost have it working, it’s just the day that i’m struggling with now. $newday outside of the shortcode is displaying fine, but when used in the shortcode, the entire shortcode stops working. Here is the code below:

    <?php
    global $wpdb;
    $canUpdate = false;
    $currentDay = date(“Y-m-d”);

    $query = “SELECT event_name, event_start_date, event_start_time FROM wp_em_events WHERE event_start_date > ‘”.$currentDay.”‘ AND event_status = 1 ORDER BY event_start_date ASC LIMIT 1″;
    $result = $wpdb->get_results($query);
    if ($result) {
    $canUpdate = true;

    foreach($result as $row)
    {
    $nextEventName = $row->event_name;
    $nextEventDate = $row->event_start_date;
    $nextEventTime = $row->event_start_time;
    $nextEventDateAr = explode(“-“, $nextEventDate);
    $nextEventTimeAr = explode(“:”, $nextEventTime);
    $nextEventYear = $nextEventDateAr[0];
    $nextEventMonth = $nextEventDateAr[1];
    $nextEventDay = $nextEventDateAr[2];
    $nextEventHour = $nextEventTimeAr[0];
    $nextEventMinutes = $nextEventTimeAr[1];
    $nextEventSeconds = $nextEventTimeAr[2];
    }
    }

    $mydate = strtotime(‘$nextEventDay’);
    $newday = date(‘l’, $mydate);
    echo $newday;
    ?>
    [countdown
    title=””
    event=”<?= $nextEventName ?>”
    date=”<?= $newday ?>”
    hour=”<?= $nextEventHour ?>”
    minutes=”<?= $nextEventMinutes ?>”
    seconds=”<?= $nextEventSeconds ?>”
    format=”DHMS”]

    Thread Starter Menno1987

    (@menno1987)

    When i try to get the date from PHP, the counter breaks also.
    I’ve tried getting the entire date in correct format as stated below, just the day, just the month or just the year. The rest of the code is working just fine, and it’s picking up the next upcoming event. Could anyone please help me with this? I think i might be outputting the date wrong with PHP or something, i’ve been pulling my hair out for like 2 days now. Any help would be much appreciated.

    The other shortcode i’ve tried. The code below is based on the big block of PHP im my last post.

    $date = new DateTime($nextEventDate);
    $result = $date->format(‘d F Y’);

    [countdown event=”Event with hour & minutes” date=”12 june 2015″ hour=”<?= $nextEventHour ?>” minutes=”<?= $nextEventMinutes ?>”]

    What output are you getting vs. what you need?

    Thread Starter Menno1987

    (@menno1987)

    I’ve already got it working now using another plugin that enables PHP and shortcodes in a widget. I wanted to create a countdown timer that counts down to the first next event made with the plugin Events Manager.
    With the code below i finally got it working. It counts down to the first next event that takes place on atleast the next day. For my client that was just fine.

    <?php
    global $wpdb;
    $canUpdate = false;
    $currentDay = date("Y-m-d");        
    
    $query = "SELECT event_name, event_start_date, event_start_time FROM wp_em_events WHERE event_start_date > '".$currentDay."' AND event_status = 1 ORDER BY event_start_date ASC LIMIT 1";
    $result = $wpdb->get_results($query);
    if ($result) {
    	$canUpdate = true;
    
         foreach($result as $row)
    	 {
    		 $nextEventName = $row->event_name;
    		 $nextEventDate = $row->event_start_date;
    		 $nextEventTime = $row->event_start_time;
    		 $nextEventDateAr = explode("-", $nextEventDate);
    		 $nextEventTimeAr = explode(":", $nextEventTime);
    		 $nextEventYear = $nextEventDateAr[0];
    		 $nextEventMonth = $nextEventDateAr[1];
    		 $nextEventDay = $nextEventDateAr[2];
    		 $nextEventHour = $nextEventTimeAr[0];
    		 $nextEventMinutes = $nextEventTimeAr[1];
    		 $nextEventSeconds = $nextEventTimeAr[2];
         }
    }
     ?>
    [countdown
    event="<?= $nextEventName ?>"
    day="<?= $nextEventDay ?>"
    month="<?= $nextEventMonth ?>"
    year="<?= $nextEventYear ?>"]
    caimin_nwl

    (@caimin_nwl)

    Great, thanks for sharing the code – might help someone else.

    Abdul Samad

    (@abdul-samad-k-t)

    Is there any plugin to do that?

    does this work beyond the next day? i.e. recurring weekly events?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Countdown/timer for next event’ is closed to new replies.