Reverse Chronological

Home Forums Calendar Products Events Calendar PRO Reverse Chronological

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #953463
    Simon
    Participant

    Hi,

    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

    #953466
    Simon
    Participant

    I 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.

    #953533
    Barry
    Member

    Hi 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 🙂

    #953556
    Simon
    Participant

    Hi 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.

    #953797
    Simon
    Participant

    If my callback is running for all queries, then why not the AJAX queries?
    How would additional testing help it apply to AJAX queries?

    #953805
    Barry
    Member

    Hi 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 🙂

    #953965
    Simon
    Participant

    Thanks 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!

    #953984
    Barry
    Member

    Awesome – fellow team member Gustavo is to credit for that snippet/plugin – and no problem, we’ll leave the topic open for the time being 🙂

    #955144
    Simon
    Participant

    Thanks Barry and Gustavo. Client is happy : )

    #955156
    Barry
    Member

    Fantastic, I’m glad we could help 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Reverse Chronological’ is closed to new replies.