Get a link of the most recent event(single event)

Home Forums Calendar Products Events Calendar PRO Get a link of the most recent event(single event)

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1213136
    Woong
    Participant

    Hi, I am working with Modern Tribe The Events Calendar Pro. I am working in Version 4.3.3 Calendar Pro, and 4.3.5 Calendar.

    I’m just looking for how to get a link of the most recent single event page, so that I can add the link to my top navigation menu.

    Unfortunately, everytime a new event is added, I have to change the link on the menu.

    Is there any way to solve this?

    If so, please let me know. thanks.

    #1213467
    Nico
    Member

    Hey Woong,

    Thanks for getting in touch with us!

    Unfortunately there’s no such a link available to add to a menu. Maybe you can create a page that redirects to the newest event single page? In this case you would have a fixed link (like http://sitename/latest-event) and with a snippet that page could redirect to the newest event. Does that makes sense to you?

    Please let me know about it and I’ll help you out with the snippet,
    Best,
    Nico

    #1213508
    Woong
    Participant

    Hi Nico,
    Thank you very much for the prompt reply.

    That is one of the ways I thought, but I could not find that.
    That makes sense!

    How can I make the newest event page?(with existing single event template?)

    Thanks!

    • This reply was modified 9 years, 4 months ago by Woong.
    #1214009
    Nico
    Member

    You are welcome Woong! Thank YOU for following up ๐Ÿ™‚

    How can I make the newest event page?(with existing single event template?)

    The idea I was suggesting was to create a WordPress standard page from the admin area, as a placeholder. For example I created a page called ‘Next upcoming event’, then with the following snippet (past it in your theme’s (or child theme’s) functions.php file) when the page is viewed it will redirect users to the next upcoming event:

    /* Tribe, redirect page to the next upcoming event */
    function tribe_redirect_to_next_event ( ) {

    // bail if not the most recent event page
    // CHANGE THE SLUG FOR THE ONE IN YOUR SITE
    if ( !is_page('next-upcoming-event') ) return;

    // retrieve the next upcoming event
    $event = tribe_get_events( array(
    'posts_per_page' => 1,
    'start_date' => date( 'Y-m-d H:i:s' )
    ) );

    // bail if no upcoming event
    if ( empty($event) ) return;

    // redirect
    wp_redirect( tribe_get_event_link( $event[0]->ID ) );
    exit;
    }
    add_action( 'wp', 'tribe_redirect_to_next_event' );

    Please give this a try and let me know if it works for you,
    Best,
    Nico

    #1214872
    Woong
    Participant

    Thanks, Nico.

    It works well!

    But, I wonder whether the solution make some performance issues.
    Because whenever people connect our website, there must be redirections right?
    I don’t think it’s a huge thing, but I’m just curious about that.

    Regards,
    Woong.

    #1215624
    Nico
    Member

    You are welcome Woong! Stoked to hear this worked for you ๐Ÿ™‚

    … whenever people connect our website, there must be redirections right?

    Well not really, the first part of the snippet check if the current page is the correct one, and in that case it makes the redirect. If the user is viewing any other pages there won’t be any redirects.

    Have you noticed any slowdowns? Have you changed the page slug for the correct one?

    Please let me know about it,
    Best,
    Nico

    #1217116
    Woong
    Participant

    Hi Nico,

    Never noticed any slow downs, actually but just curious about that.
    Thanks for your help.

    Best,
    Woong.

    #1217547
    Nico
    Member

    Perfect! Thanks for confirming Woong!

    Iโ€™ll go ahead and close out this thread, but if you need help with anything else please donโ€™t hesitate to create a new one and we will be happy to assist you.

    Best,
    Nico

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Get a link of the most recent event(single event)’ is closed to new replies.