Feasible to display live current date instead of start date for date range?

Home Forums Calendar Products Events Calendar PRO Feasible to display live current date instead of start date for date range?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1173910
    pixelcrane
    Participant

    Hi there people who make the world go round!

    Here is the scenario… let’s say we have an event that goes from August 15, 2016 – October 31, 2016. Is it feasible to have the front end display:

    Event Name
    <dynamicCurrentDate> – October 31, 2016

    -instead of-

    Event Name
    August 15, 2106 – October 31, 2016

    Logically this would have to auto-update and display the actual date at midnight every day from August 15, 2016 – October 31, 2016. Then, on October 31, 2016 the event would display as…

    Event Name
    October 31, 2016

    You can see how the reasoning would apply to the site we have at http://www.jhparkcity.com/events/

    Specifically, my questions would be applicable for events like ‘Endangered Landscape Exhibits’ and ‘Dealer’s Choice Exhibit’

    Gracias!

    #1174196
    George
    Participant

    Hey @pixelcrane,

    Thanks for stopping by.

    Doing this is possible, though a little tricky. Per our support policy we unfortunately cannot help with writing custom snippets and such, but I’ve gone ahead and made a proof-of-concept snippet here for you that should at least help you get started!

    Here is that snippet:

    function tribe_add_dynamic_start_date_to_selected_events( $inner, $event_id ) {

    // If the current event is *not* in the "Dynamic Start Date" category, return normal details.
    if ( is_object_in_term( $event_id, 'tribe_events_cat', 'dynamic-start-date' ) ) {
    return $inner;
    }

    // Get timestamp of the event start time.
    $end_timestamp = tribe_get_end_date( $event_id, true, 'U' );

    // If the event is being viewed after its end time, just return the normal details.
    if ( strtotime( 'now' ) > $end_timestamp ) {
    return $inner;
    }

    return date( tribe_get_date_format(), strtotime( 'now' ) ) . ' - ' . tribe_get_end_date( $event_id );
    }

    add_filter( 'tribe_events_event_schedule_details_inner', 'tribe_add_dynamic_start_date_to_selected_events', 10, 2 );

    ☝️ Try adding this snippet to your theme’s functions.php file and let me know if it helps.

    Once the snippet is added to your theme’s functions.php file, head to an event whose start times you want to be “dynamic” in this way. Then, make an event category called “Dynamic Start Date” and give that event that category. Here is a screenshot showing this in effect:

    For any event that has that category, the start time of the event will be altered as you describe: it will show the set end date, but for the start date will show the current date.

    Now, if you’re looking at a passed event, then it will just show the set start date. You didn’t specify this feature, but I added because it seems to make sense to me.

    For example, let’s say today is October 10th.

    For one “Dynamic Start Date” event, its start date is October 1 and its end date is October 15th. When you view it, it’s schedule details will say, “October 10 – October 15”.

    Now let’s say there’s another event that started October 1, and ended October 5. Even though it has the “Dynamic Start Date” category, when you view it its schedule details will say, “October 1 – October 5”, because it wouldn’t make sense if it said it started October 10 and ended October 5!

    The snippet I shared here is just a starting place; take it, tinker with it, etc. I hope it helps! 😀

    — George

    #1185055
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Feasible to display live current date instead of start date for date range?’ is closed to new replies.