• Resolved Rhapsody348

    (@rhapsody348)


    I have AI1EC installed and have created a category called “Key Events” so I can display those events I choose in a sidebar Widget. The widget currently displays the date for the event, the title and location. I would like it to also display the number of days until the event. I created a shortcode that is included in the functions.php that will calcualte the number of days until the event. If I enter the shortcode [cdt][/cdt] in the text field for the event it displays the number of days properly. If I put the shortcode in the title of the event, it does not display properly. Only the [cdt][/cdt] text is displayed.

    Is there a way that I can get AI1EC to display the number of days to an event in the sidebar widget with the date & title?

    Below is the code stored in the functions.php file in my child theme.

    function content_countdown($atts, $content = null){
    // This section gets the Unix timestamp stored for the event and converts to month, day and year
    // Get the start date data from the ai1ec_events table in the WordPress database.
    global $wpdb;
    $postid = get_the_ID(); // gets the current post ID associated with the event
    $timestamp = $wpdb->get_var("SELECT start FROM wp_ai1ec_events WHERE post_id = $postid");
    $month = date('m', $timestamp); // 1-12
    $day = date('d', $timestamp); // 1-31
    $year = date('Y', $timestamp); // 4 digit year
    
    // this code lifted from code snippet but uses event date from wp table rather than numbers passed from shortcode
    //  extract(shortcode_atts(array(
    //     'month' => '',
    //     'day'   => '',
    //     'year'  => ''
    //    ), $atts));
        $remain = ceil((mktime( 0,0,0,(int)$month,(int)$day,(int)$year) - time())/86400);
        if( $remain > 1 ){
            return $daysremain = "<div class=\"event\"><b>$remain</b> days until this event</div>";
        }else if($remain == 1 ){
            return $daysremain = "<div class=\"event\"><b>$remain</b> day until this event</div>";
        }else{
            return $content;
        }
    }
    add_shortcode('cdt', 'content_countdown');

    https://www.ads-software.com/plugins/all-in-one-event-calendar/

  • The topic ‘How to display "Days until event"’ is closed to new replies.