Default to first event on Month View

Home Forums Calendar Products Events Calendar PRO Default to first event on Month View

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1113176
    Chris
    Participant

    Using Events Calendar Pro, I’m looking to have the Month view of the calendar default to the first month there is an event, not the current month. So if it is currently May, and my next even isn’t until September, I’d like the Month view to default to September. Is this possible?

    #1113494
    Andras
    Keymaster

    Hi Chris,

    Thanks for going PRO and reaching out!

    It is possible to change the default view of the calendar, however it influences all views, not only the month view.

    Check out this knowledgebase article for the details.

    Let me know if this is of any use or if you need some more help.

    Cheers,
    Andras

    #1113511
    Andras
    Keymaster

    Hi again Chris,

    I reached out to my colleagues and got a fast response. Try this snippet, just copy-paste this code in your functions.php file (Appearance > Editor > choose functions.php on the right side):


    /*
    * In month view the month with the first upcoming event is shown
    */
    add_action( 'tribe_events_pre_get_posts', 'fast_forward_month_view' );
    function fast_forward_month_view( $query ) {
    // Don't interfere with other month views (like mini-cal)
    if ( ! $query->is_main_query() ) return;
    // Don't interfere outside of month view
    if ( 'month' !== $query->get( 'eventDisplay' ) ) return;

    // Get the first upcoming event (bail if there is none)
    $upcoming = tribe_get_events( array( 'posts_per_page' => 1, 'eventDisplay' => 'list' ) );
    if ( empty( $upcoming ) ) return;

    // Set month view to the first upcoming event
    if ( ! $query->get( 'eventDate' ) ) $query->set( 'eventDate', $upcoming[0]->EventStartDate );
    }

    Share the results with me.

    Cheers,
    Andras

    #1114204
    Chris
    Participant

    This worked great. Thank you!

    #1114470
    Andras
    Keymaster

    Hey Chris,

    I’m super happy this helped.

    I am going to go ahead and close this ticket, but if you need help on this or something else, feel free to open a new one.

    Cheers,
    Andras

    #1114471
    Andras
    Keymaster

    🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Default to first event on Month View’ is closed to new replies.