Chronologically show 'Related Events' on Single Event Page

Home Forums Calendar Products Events Calendar PRO Chronologically show 'Related Events' on Single Event Page

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1208839
    Brian
    Participant

    In reference this this old post:

    https://theeventscalendar.com/support/forums/topic/order-related-events/

    Where do I add the code snippet to accomplish the same outcome as requested in that forum thread.

    I have also purchased Advanced Post Types Order and Taxonomy Terms but I cannot get them to work properly on any post type. This code looks like it will accomplish exactly what I want to do.

    Thanks in advance.

    #1209200
    Nico
    Member

    Hi there Brian,

    Thanks for getting in touch with us!

    You should place the code in your theme’s (or child theme’s) functions.php file:

    https://gist.github.com/elimn/1e6797dd1a5d8ee666c5

    The sample above is a reference Cliff sent to the customer. Do you think you can tweak it as he explains? In case you are not sure about it let me know and I can help you out.

    Best,
    Nico

    #1209204
    Brian
    Participant

    Thanks for your reply. I can copy and paste with the best of them but customizing anything usually breaks my site and my spirit. I would love to have the help.

    What I would like to do is have the ‘Related Events’ showing on a single event page:

    1) display the next events sequentially and in order
    example – Main event is on a Monday. I would like the related events show Tuesday, Wednesday, Thursday in that order below.

    AND (here’s the kicker)

    2) be related based on the category of the Main Event.
    example – I have a rehearsal category and a performance category. I do not want a rehearsal category event to show up as a Related Event on the bottom of a Performance category event (and vice versa).

    Thanks again.

    #1211858
    Nico
    Member

    Thanks for following-up Brian!

    I can copy and paste with the best of them but customizing anything usually breaks my site and my spirit. I would love to have the help.

    Sure, why cannot help much with customizations but this one is fairly easy so no problem with helping you out!

    Just paste this code in your theme’s (or child theme’s) functions.php file:

    /* Tribe, change related posts arguments */
    function tribe_modify_related_posts_args ( $args ) {

    $args['meta_key'] = '_EventStartDate';
    $args['orderby'] = 'meta_value';
    $args['order'] = 'ASC';

    return $args;
    }

    add_filter( 'tribe_related_posts_args', 'tribe_modify_related_posts_args' );

    Now, regarding the criteria to relate events by default the code looks into related events by tags AND event categories. If you only use event categories there shouldn’t be any problems with events mixing from different categories. Now, if you also use tags to relate these, then I can amend the snippet to just look into categories and not tags.

    Please let me know about it,
    Best,
    Nico

    #1211899
    Brian
    Participant

    Thanks very much. I copied the code and pasted it into the functions.php file in my child theme folder. After testing, it appears that the related categories portion worked as needed but when viewing any event, the related items showing are not the next upcoming three events. It always shows the first three events in that related category.

    It seems so close to being what we need on our site. Is there another bit of code that can be added to display the next three upcoming related events based on the event being viewed?

    [I tried in Chrome and Safari and cleared cache after uploading changes to php file but results were the same. I’m attaching a screenshot showing the detail view of an event in February but the related items are still showing the first three events in January.]

    Thanks again.

    #1212259
    Nico
    Member

    Thanks for following up Brian!

    After testing, it appears that the related categories portion worked as needed

    The code sent was just changing the order of the related events, not the ‘relation’ criteria. As said before if you only use event categories to relate events (and not tags) you shouldn’t see any events from other categories.

    when viewing any event, the related items showing are not the next upcoming three events. It always shows the first three events in that related category.

    Not sure about this. You just want the three next events, but not the related ones, but from any category? I mean, just the next three upcoming events, regardless any relation with the actual event?

    Please let me know about it,
    Best,
    Nico

    #1212335
    Brian
    Participant

    Thanks. For clarification, I want to see the next three events that are scheduled in relation to the event detail that is being viewed.

    For this example, let’s assume I have an event on everyday of the week:

    When clicking on Monday’s event and viewing it’s detail page, I want to see the next three related events in the proper order; those would be Tuesday, Wednesday, Thursday in that order.

    When clicking on Wednesday’s event and viewing it’s detail page, I want to see the next three related events in the proper order; those would be Thursday, Friday, Saturday.

    #1213172
    Nico
    Member

    Thanks for following up Brian! Now we are on the same page 😉

    Try this updated version of the snippet:


    /* Tribe, change related posts arguments */
    function tribe_modify_related_posts_args ( $args ) {

    // show upcoming events in relation with original post start date
    $args['eventDisplay'] ='custom';
    $args['start_date'] = tribe_get_start_time( $args['post__not_in'][0], 'Y-m-d H:i:s' );

    // order by start date
    $args['orderby'] = 'event_date';
    $args['order'] = 'ASC';

    return $args;
    }

    add_filter( 'tribe_related_posts_args', 'tribe_modify_related_posts_args' );

    It should still order events by start date, but it will now show only events taking place after the original event date.

    Please let me know if it’s working as you need it to,
    Best,
    Nico

    #1224397
    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 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Chronologically show 'Related Events' on Single Event Page’ is closed to new replies.