WordPress.org

Ready to get started?Download WordPress

Forums

The Events Calendar
[resolved] Showing past evens in WP loop (28 posts)

  1. pealo86
    Member
    Posted 1 year ago #

    I'm using the following arguments in a query:

    $args = array(
    		'post_type' => 'tribe_events',
    		'posts_per_page' => -1,
    		'orderby' => 'title'
    );
    query_posts($args);

    However it is only showing future events, not those that have passed.

    Is there a way to simply pull in all events rather than the future ones?

    http://wordpress.org/extend/plugins/the-events-calendar/

  2. kingproductions
    Member
    Posted 1 year ago #

    I've asked right the same thing...let's hope together! ;)

  3. Stuart Blackett
    Member
    Posted 1 year ago #

    I'm asking the same thing too.

    My query to get this is :

    $events = new WP_Query();
    $events->query('post_type=tribe_events&meta_key=_EventStartDate&posts_per_page=-1&eventDisplay=all&orderby=_EventStartDate&order=DESC');

    However the order just doesnt seem to be working. Wonder if any of the dev's know how to overwrite their query?

    Looking at a var_dump of $events I can see the query being run, But it does not change to DESC at all.

    Is this a bug?

  4. roblagatta
    Modern Tribe Support
    Plugin Author

    Posted 1 year ago #

    Wow, lots of requests for this - interestingly enough we hadn't heard really any requests for this prior to this month, but in my rounds on the forum today I've counted no fewer than 3.

    Let me get Paul, our developer on this plugin who is far more knowledgeable on the code side than I, to take a look at Stuart's last note and comment directly. Stay tuned here, guys, and thanks for your patience so far.

  5. jonahcoyote
    Member
    Posted 1 year ago #

    Hey all,

    You should use tribe_get_events when using event specific args like eventDisplay. Here is an example of a query getting past events: https://gist.github.com/3427287

    I hope that helps but let me know if you guys need anything else!

    Cheers,
    Jonah

  6. jonahcoyote
    Member
    Posted 1 year ago #

    FYI, you cannot use our plugins arguments in WP_Query.

  7. Stuart Blackett
    Member
    Posted 1 year ago #

    Hi jonahcoyote, Your code is pretty much a carbon copy of what I have made barring the "past" being add, I need all events and ordered by date. Showing the latest at the top, The oldest at the bottom.

  8. jonahcoyote
    Member
    Posted 1 year ago #

    Hi stuart@koodoocreative.co.uk,

    As I said you cannot use the eventDisplay arg along with WP_Query so that's why what you're trying to do is not working. You need to use tribe_get_events instead and the code example I posted gives you a sample of how to do this. Does that make sense?

    - Jonah

  9. pealo86
    Member
    Posted 1 year ago #

    This is a great plugin but my mind is boggled as to why we can't treat Events posts as we would any normal post or custom post?

  10. Stuart Blackett
    Member
    Posted 1 year ago #

    Hi jonahcoyote. Looking at your "example" code. There are no params which are going to help me achieve what I would like. Which is order the posts by date ASC or DESC? Can you explain this further?

    I also agree with pealo86, why cant this plugin use the WP Query. I have mine working with WP Query, just the order is not working. However if there is a justifiable reason why you have to use tribe_get_events then I will revert back to it and can I just say I am dissapointed by the support for this plugin. I understand that this is something that wasnt initially included in the release, But the fact that myself and others are still asking weeks nearly months later doesnt bode well...

    Thanks

  11. jonahcoyote
    Member
    Posted 1 year ago #

    @pealo86 - event posts can and treated like normal custom posts. How are they not? You can use WP_Query but you cannot use certain plugin specific arguments (eventDisplay for example) in the query.

    @Stuart - I think the reason this is not working is that it doesn't look like there's an easy way to orderby a meta_key that contains date values... It should be possible but I would suggest digging around a little on Google to see if you can find some examples. Using the stock WP_Query arguments, it doesn't seem like you can accomplish this.

    I hope that helps but let me know if you need anything else.

    - Jonah

  12. pealo86
    Member
    Posted 1 year ago #

    Me posting this very thread would suggest how Events posts are handled differently to ordinary posts or custom posts. E.g. I cannot work with them using query_posts if the event has already passed.

    Also there's this:
    http://wordpress.org/support/topic/plugin-the-events-calendar-cannot-change-order-of-posts-in-query_posts

    And this:
    http://wordpress.org/support/topic/plugin-the-events-calendar-trouble-echoing-certain-meta-values

    As I say, a great plugin, but it would make more sense if I could just handle the posts like any other.

  13. Stuart Blackett
    Member
    Posted 1 year ago #

    Hi @pealo86 did you manage to solve this? I've now got my events order by EventStartDate after using the sort_query_posts_by plugin. However it is now ordering it by the month in descending order (A-Z).

  14. Barry
    Member
    Posted 1 year ago #

    Hi guys, I think Rob and Jonah have already covered a lot here but just to pick up on the idea that you can't query events which have already past, I don't find this to be true.

    This code for instance http://pastebin.com/s8pHSik7 returns events from last month if I run it on my test setup.

  15. pealo86
    Member
    Posted 1 year ago #

    @Stuart Nope I didn't I'm afraid! Luckily it wasn't a major requirement of the job.

    @Barry Ahhh right I didn't realise this! I should set the post type as 'TribeEvents::POSTTYPE' when performing a query?

    I'll try that next time.

    Thanks!

  16. Barry
    Member
    Posted 1 year ago #

    TribeEvents::POSTTYPE is just a class constant - ultimately you are still passing a string ('tribe_events') and the effect should be the same.

  17. pealo86
    Member
    Posted 1 year ago #

    I see! Hmmmmm.

    Do you think my problem could be down to me not using the class constant previously?

  18. Barry
    Member
    Posted 1 year ago #

    No, not really. What you did isn't wrong and actually if I run your code it produces the same results as mine - once again I am seeing events published before today's date.

    The important thing to remember is that the date the event was published, or post date, is quite different from the event date. Perhaps that is causing some confusion here?

    What we can say is that if you want to handle events like regular (custom) posts then you can ... but if you need to run event/date specific queries against them then query_posts() is unlikely to cut the mustard and, just like Jonah suggested, you would need to go about this The Events Calendar way and use functions such as tribe_get_events().

  19. pealo86
    Member
    Posted 1 year ago #

    Hmmmm strange!

    Thanks for the tips, I'll go with tribe_get_events() from now on.

  20. roblagatta
    Modern Tribe Support
    Plugin Author

    Posted 1 year ago #

    Great to hear, pealo86 - thanks for the follow-up. It sounds like based on what I'm reading above, you should be set here...but can you guys confirm if anyone else is having any issues here? I'll close the thread out if so.

  21. Stuart Blackett
    Member
    Posted 1 year ago #

    I also used tribe_get_events although still couldnt do an ordered full event list. So created an "Past Events" page as well as an upcoming events page.

    Not ideal, But client is happy.

  22. roblagatta
    Modern Tribe Support
    Plugin Author

    Posted 1 year ago #

    Thanks for confirming, Stuart. Did you see Jonah's last note? Was that able to point you in the right direction at all? Sounds like if the client is happy you're good for now, but if this does become a pain point again and if Jonah's idea isn't helpful...let us know and we can jump back into it. Going to mark the thread RESOLVED for now though, unless you disagree...

  23. Sebastian G K
    Member
    Posted 1 year ago #

    Hello,

    Just wanted to open this thread up again, as this is something I've been looking to sort out for a while.

    This is to use in a header or a sidebar, so I'd like to be able to call this from anywhere.

    Using a custom WP_QUERY()
    I am able to pull all events, past and present in one query.
    This does exactly what I want, but for some reason it will only query all the posts when I am on an "single event" page.

    When I go out of a "single event" context, be it the calendar, list view or any other wp page or post it will only query upcoming events.

    I can't seem to find any good fix for this.

    I also trued using the tribe_get_events() loop only allows me to order events when I use either 'eventDisplay'=>'past' or 'eventDisplay'=>'upcoming'

    It would be incredibly useful in some projects to be able to use for example 'eventDisplay'=>'all' and order by whichever field I want ascending or descending.

    The only way it seems to do this right now, is to write all the content to an array with the foreach loop, reverse it and then print? Not very elegant but I will try and see how it goes.

    Cheers
    s

  24. jonahcoyote
    Member
    Posted 1 year ago #

    Hi Sebastian G K,

    Mind posting your query code here?

    Thanks,
    Jonah

  25. Sebastian G K
    Member
    Posted 1 year ago #

    Hello Jonah,

    The standard WP query:

    $args = array(
    	'post_type' => 'tribe_events',
    	'posts_per_page' => 3,
    	'meta_key'=>'_EventStartDate',
    	'orderby' => 'meta_value',
    	'order' => 'DESC'
    	);
    $loop = new WP_Query( $args );

    Which does pull all single pages. (I just realised that it not only gets the correct data on single event but also on single post.)

    In this case I want the three latest events ordered descending from the EventStartDate so I get all the tribe events as an array, reverse the array, and slice it.
    Then I can iterate through the resulting array in the order I want.

    I don't actually know if 'eventDisplay'=>'all', does anything, but without it I get the same problem as with the custom WP loop. Only shows all events on single pages/event.

    $events = tribe_get_events(array(
    	'eventDisplay'=>'all',
    	'orderby' => 'EventStartDate',
    	'posts_per_page'=>-1
     ));
    
    $events = array_reverse($events);
    $events = array_slice($events, 0, 3);
    
     foreach($events as $post) {
    	setup_postdata($post);
    
    	// print content here
     }

    This works fine for me really, would be good if it was built in, but apart from potentially pulling hundreds of events, right now it does the job. I will use some form of caching here so to stop it from running this code too often.

    I hope it can be of help to anyone in the same situation.

    Seb

  26. jonahcoyote
    Member
    Posted 1 year ago #

    Hi Seb,

    I'm still not quite what you are asking for. Are you just wanting more ways of being able to sort events using tribe_get_events() or WP_Query? One thing that may help when using WP_Query is identifying the post_type like so:

    'post_type'      => array(TribeEvents::POSTTYPE),

    That should allow you to use many of the standard query args like you normally would.

    - Jonah

  27. Sebastian G K
    Member
    Posted 1 year ago #

    Hello,

    I'd just like to be able to pull out all the events, without having to specify if they are past or upcoming.

    I can do this via a standard wp_query, but it seems to only loop through all events when I'm on an event or post single page.

    I don't know if it has something to do with the permalink structure? This might be slightly unrelated, but I had to turn on "nice" permalinks to get my navigation working when the Events Calendar plugin was activated. My events menu only turned up on event and post single.

    Seb

  28. jonahcoyote
    Member
    Posted 1 year ago #

    Hmmm, it could be a conflict with your theme or another plugin too. Have you tried deactivating all other plugins and or switching themes to Twenty Eleven?

    - Jonah

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.