Home › Forums › Calendar Products › Events Calendar PRO › Reverse Chronological
- This topic has 9 replies, 2 voices, and was last updated 11 years ago by
Barry.
-
AuthorPosts
-
April 6, 2015 at 8:07 am #953463
Simon
ParticipantHi,
I’ve tried this in my functions.php to reverse the order of events in List view:
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 || tribe_is_upcoming() /* && !is_tax() */ ) { $post_object = array_reverse($post_object); } return $post_object; } add_filter('the_posts', 'tribe_past_reverse_chronological', 100);But it doesn’t work with AJAX. If you reload the page it does work.
So I tried disabling AJAX, but that stops the Previous / Next links working at all. They show the same original view when clicked.
If possible I would prefer to have it working with AJAX, but failing that then I suppose disabling AJAX is an option.
Note: I’m using the basic version of the plugin, although I do own Pro and can install it if needed to fix the issue.
Many thanks
April 6, 2015 at 8:15 am #953466Simon
ParticipantI should mention that the default List view works.
It doesn’t work if you click Previous or Next.
After clicking Previous or Next, reloading the page works.
So there’s probably something not right with $past_ajax.April 6, 2015 at 1:51 pm #953533Barry
MemberHi Simon,
Interesting problem.
How about accepting two variables in your callback (the first being the array of posts, which you currently use, the second being the actual query object they relate to) – you could then test for:
- The presence and value of the eventDisplay query var
- Whether the query has a tribe_is_event_query property which is set to true
Might that help you out here?
Right now, for instance, your callback runs for all queries (not just the main or ajax event query) which is likely to be something you should modify in any case.
I hope that helps/gives you a few ideas 🙂
April 6, 2015 at 3:13 pm #953556Simon
ParticipantHi Barry,
I don’t know the inner workings of those queries.
I literally got the code from this support thread.
It’s a snippet provided by Geoff from support.April 7, 2015 at 11:59 am #953797Simon
ParticipantIf my callback is running for all queries, then why not the AJAX queries?
How would additional testing help it apply to AJAX queries?April 7, 2015 at 12:31 pm #953805Barry
MemberHi Simon,
You could alternatively use (and adapt) this code which can be downloaded as a plugin zip for your added convenience:
github.com/bordoni/tec-forum-support/tree/plugin-945676
Do note that it is interested in past view only (see line 37) but you could remove the reference to $query->tribe_is_past if that’s undesirable in your case.
Last but not least, please note that snippets/helper plugins like this are provided in the hope that they’ll be useful, but if they don’t completely meet your needs it’s often the case that you’ll need to tweak, adapt and improve them 🙂
April 8, 2015 at 2:13 am #953965Simon
ParticipantThanks so much Barry. I think that did the trick!
I’ll leave this open for a few hours whilst the client tests the site to see if all is ok.
If so, I’ll close the ticket.
Thanks again!April 8, 2015 at 6:29 am #953984Barry
MemberAwesome – fellow team member Gustavo is to credit for that snippet/plugin – and no problem, we’ll leave the topic open for the time being 🙂
April 13, 2015 at 11:51 am #955144Simon
ParticipantThanks Barry and Gustavo. Client is happy : )
April 13, 2015 at 12:14 pm #955156Barry
MemberFantastic, I’m glad we could help 🙂
-
AuthorPosts
- The topic ‘Reverse Chronological’ is closed to new replies.
