Home › Forums › Calendar Products › Events Calendar PRO › Recurring Events starting at the last event
- This topic has 7 replies, 3 voices, and was last updated 9 years, 10 months ago by
Brook.
-
AuthorPosts
-
July 3, 2016 at 7:53 pm #1135003
Jason
ParticipantI am displaying the 3 soonest upcoming events on my homepage using this code I found here (https://theeventscalendar.com/support/forums/topic/calling-event-listing-onto-homepage/)
<? $posts_array = get_posts('post_type=tribe_events'); foreach ( $posts_array as $post ) : setup_postdata( $post ); ?> <div class="shadow"> <div class="col-lg-4"> <div id="post-<?php the_ID() ?>" class="<?php tribe_events_event_classes() ?>"> <?php tribe_get_template_part( 'list/single', 'event' ) ?> </div><!-- .hentry .vevent --> </div><!--End Col--> </div><!--End Shadow--> <?php endforeach; ?>the problem is it is acting buggy and skipping my soonest reccuring event (September 16 is showing but not Sept. 9) also not removing events that have already passed and other things…
So my questions are:
1. How can I make sure the 3 soonest upcoming events are being displayed?
2. How can I make sure an event that has ended isn’t displayed?
3. How can I make sure recurring events don’t display out of order?Thanks for your help.
July 4, 2016 at 10:57 pm #1135326Brook
ParticipantHowdy Jason,
I would love to help you with this.
Have you seen tribe_get_events() ? It’s basically a drop-in replacement for get_posts as used in your link, and it behaves exactly how you want. Instead of :
$posts_array = get_posts('post_type=tribe_events');I believe this will do exactly what you need:
$posts_array = tribe_get_events( array( 'posts_per_page' => 3, ) );Did that fit your needs?
Cheers!
– Brook
July 4, 2016 at 10:57 pm #1135327Brook
ParticipantHowdy Jason,
I would love to help you with this.
Have you seen tribe_get_events() ? It’s basically a drop-in replacement for get_posts as used in your link, and it behaves exactly how you want. Instead of :
$posts_array = get_posts('post_type=tribe_events');I believe this will do exactly what you need:
$posts_array = tribe_get_events( array( 'posts_per_page' => 3, ) );Did that fit your needs?
Cheers!
– Brook
July 10, 2016 at 6:44 am #1137900Jason
ParticipantBrook, thanks for your help. That did the trick. My only problem now is an event that has already occurred is still being displayed. How do I only show future events and not expired ones?
Thanks,
JasonJuly 11, 2016 at 11:24 pm #1138544Brook
ParticipantHowdy Jason,
You are welcome!
$events = tribe_get_events( array( 'posts_per_page' => 5, 'start_date' => date( 'Y-m-d' ) ) );
Replacing it with that will do a date range search from now forward. So it should show the next 5 upcoming events as it sounds like you expect. It will also show any ongoing events, namely events that have not ended yet but started recently.
Did that do the trick?
Cheers!
– Brook
July 12, 2016 at 4:53 am #1138588Jason
ParticipantThanks man. Got it working.
July 12, 2016 at 7:11 am #1138617Brook
ParticipantAwesome! It was my pleasure.
Do let us know if you ever need anything else. Thanks Jason!
– Brook
-
AuthorPosts
- The topic ‘Recurring Events starting at the last event’ is closed to new replies.
