Recurring Events starting at the last event

Home Forums Calendar Products Events Calendar PRO Recurring Events starting at the last event

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1135003
    Jason
    Participant

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

    #1135326
    Brook
    Participant

    Howdy 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

    #1135327
    Brook
    Participant

    Howdy 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

    #1137900
    Jason
    Participant

    Brook, 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,
    Jason

    #1138544
    Brook
    Participant

    Howdy 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

     

    #1138588
    Jason
    Participant

    Thanks man. Got it working.

    #1138617
    Brook
    Participant

    Awesome! It was my pleasure.

    Do let us know if you ever need anything else. Thanks Jason!

    – Brook

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Recurring Events starting at the last event’ is closed to new replies.