Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MT | TEC | Change past event views to reverse chronological order
<?php
// Changes past event views to reverse chronological order
function tribe_past_reverse_chronological ($post_object) {
$past_ajax = (defined( 'DOING_AJAX' ) && DOING_AJAX && $_REQUEST['tribe_event_display'] === 'past') ? true : false;
if(tribe_is_past() || $past_ajax) {
$post_object = array_reverse($post_object);
}
return $post_object;
}
add_filter('the_posts', 'tribe_past_reverse_chronological', 100);
@martham

This comment has been minimized.

Copy link

martham commented Dec 6, 2014

This is also reversing the order of the Upcoming Events widget if it is on the same page. Is there a way to limit this to non-widget lists only?

@elimn

This comment has been minimized.

Copy link
Owner Author

elimn commented Dec 18, 2014

Hello Martha, that is unfortunately a setup that this snippet can not support. More information in this topic on how to create a theme override and modify this snippet to work in that sceanrio: https://theeventscalendar.com/support/forums/topic/display-past-events-in-reverse-order-snippet/ It is not a great work around. Unfortunately I can not think of a way that the current API allows for a better one.

@baerkins

This comment has been minimized.

Copy link

baerkins commented Jan 6, 2015

For reasons unknown, this is causing some issues on my local install (using MAMP). It does work on the server, but locally I cannot save updates to pages/posts, and have issues with the media library manager within posts as well.

As I said, it works fine on live servers so far, so it's not a major issue. Any thoughts on what it could be locally?

@elimn

This comment has been minimized.

Copy link
Owner Author

elimn commented Feb 12, 2015

I am intrigued iamhexcoder. I can not think of a reason that would happen. In order for that to happen the query would at least have to have $_REQUEST['tribe_event_display'] set to past, or $wp_query->tribe_is_past set to true. That should only ever happen on event queries. Very strange. I wish I had something more to offer. My gut would say it's a caching or security solution, as I have seen both of those muck with queries, especially ajax ones.

@nschivley

This comment has been minimized.

Copy link

nschivley commented Feb 26, 2015

I have tried your code above and it works really well on the landing page for past events, but when I click the previous or next buttons, I just get the spinning dial. Any ideas? Sorry to jump on somebody else's thread but this is the only one I saw using this solution.

Here's a link to the page:
http://www.riponsociety.org/events/list/?action=tribe_list&tribe_paged=1&tribe_event_display=past

Thanks!

@albanderv

This comment has been minimized.

Copy link

albanderv commented Jun 5, 2015

Hey,
It may seem obvious, but as a beginner, i'm not really sure.
Where is this functions.php file?

I use WORDPRESS 4.2.2 under moesia, and my version of The Events Calendar is 3.9.3.

Thanks in advance :)

@ChrisChiera

This comment has been minimized.

Copy link

ChrisChiera commented Aug 9, 2015

This worked perfectly for me. So thrilled thrilled that it was finally realized as a bug rather than a feature request, since the reverse ordering of course didn't make much sense. At the same time fixing an issue like that takes a long time, so its great they have this workaround in the mean time.

@nschivley May be something in your code. I'm able to view the past page and use the previous buttons and works properly. That is no spinning wheel and shows the correct order now (newest to oldest).

@alwii Depends. If a file you would have created in your theme folder (or bought if you bought your template). So /wp-content/themes/[name of your theme folder]/ Here is where it should be or maybe in a sub folder. Or if you never created one, you can add a file called functions.php here.

@Daimda

This comment has been minimized.

Copy link

Daimda commented Oct 29, 2015

Hey guys,
when I past the code in function.php I receive this error:

Fatal error: Call to undefined function tribe_is_past() in /web/htdocs/www.selvaurbana.it/home/wp-content/themes/SF-child/functions.php on line 4

Do you know why?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.