Home › Forums › Calendar Products › Events Calendar PRO › How to show Previous Events if there are no Upcoming Events
- This topic has 5 replies, 3 voices, and was last updated 9 years, 8 months ago by Barry.
-
AuthorPosts
-
May 13, 2014 at 2:37 pm #159778simoncarrParticipant
Hi,
I’m using a custom php template to pull in some events. Code below..
Is there a way to code this so the 3 most recent past events show up if there are no upcoming events? Any help would be appreciated, thanks!
<?php
global $post;
$all_events = tribe_get_events(
array(
‘eventDisplay’=>’upcoming’,
‘posts_per_page’=>3,
)
);
foreach($all_events as $post) {
setup_postdata($post);
?>May 14, 2014 at 8:59 am #160904BarryMemberHi! Could you check the result to see if any posts were retrieved first time round ($all_events->have_posts() or else check the post_count property) then if it is apparent nothing was retrieved, run a new query but set eventDisplay to past?
May 16, 2014 at 11:18 am #163706simoncarrParticipantBarry,
Sorry – I’m not sure I follow what you are saying. Can you show me how you would structure that code?
Thanks
May 19, 2014 at 6:30 am #165941BarryMemberApologies, I forgot you don’t actually get a WP_Query object back when you use tribe_get_events(). Even so, you should receive an array as the result – so perhaps you could do something like:
$events = tribe_get_events( $your_original_query ); // Check if any events were returned if ( count( $events ) > 0 ) { // Your code to display the results } else { $events = tribe_get_events( $your_past_event_query ); // Display past events instead... }
Does that help?
May 20, 2014 at 6:59 pm #168249consoleofficeParticipantHow can I remove the section of “Upcoming Events” completely?
Thanks.
September 4, 2014 at 7:38 pm #723200BarryMemberHi: I’m very sorry we missed these follow up questions. That was, unfortunately, due to a bug in our forum software (which only notified us of updates when the original poster added a new reply). Owing to the amount of time that’s elapsed I will now close this thread and I’d ask that if you still need help you create a fresh thread: one of the team will then be only too happy to assist 🙂
Thanks!
-
AuthorPosts
- The topic ‘How to show Previous Events if there are no Upcoming Events’ is closed to new replies.