Support » Plugin: The Events Calendar » Show a message if no events?

  • Resolved rocketmatt

    (@rocketmatt)


    Hi there,

    I’m using The Events Calendar eventbrite plugins to serve events onto my client’s website, but I’m not sure how to show a message if there are no events, such as “There are no events at this time, please check back later to see if we’ve added any dates.”

    I’ve tried a few methods but have had no joy and I can’t see anything in the documentation. Any help or advise would be appreciated:

    This is the code that serves up the events:

                  <div class="courses-list">
    
                  <?php // Ensure the global $post variable is in scope
                    global $post;
    
                    $events = tribe_get_events( [ 
                      'posts_per_page' => 999, 
                      'start_date'     => 'now',
                      'tax_query'=> array(
                          array(
                              'taxonomy' => 'tribe_events_cat',
                              'field' => 'slug',
                              'terms' => 'product-owner-masterclass'
                          )
                      )
                   ] );
    
                    // Loop through the events: set up each one as
                    // the current post then use template tags to
                    // display the title and content
                    foreach ( $events as $post ) {
                      setup_postdata( $post );
                    ?>
    
                    <div class="course 
                    
                    <?php $soldout = get_field('sold_out', $post->ID);
                      if ($soldout) : ?> 
                      soldout<?php endif; ?>">
    
                      <div class="course-details">
                      <?php $multiple_dates = get_field('multiple_dates', $post->ID);
                        if ($multiple_dates) : ?>
                        <span class="date">
                          
                        <?php if (have_rows('course_dates')): ?>
    
                        <?php while (have_rows('course_dates')): the_row();
    
                            // vars
                            $date = get_sub_field('event_date');
                            $start = get_sub_field('start_time');
                            $end = get_sub_field('end_time');
    
                        ?>
    
                          <p class="single-date"><?php echo $date; ?> <?php echo $start; ?> - <?php echo $end; ?></p>
    
                        <?php endwhile; endif; ?>
    
                        </span>
                        <?php else: ?>
                        <span class="date"><?php echo tribe_get_start_date(); ?> - <?php echo tribe_get_end_date(); ?></span>
                        <?php endif; ?>
                        <span class="location">
                          <?php if (get_field('online_course')) : ?>
                            <span class="online-course">Online</span>
                          <?php else: ?>
                            <a class="open-map"><?php echo tribe_get_city(); ?>, <?php echo tribe_get_country(); ?></a>
                          <?php endif; ?></span>
                          
                          <?php if (get_field('online_course')) : ?>, <span class="lang">in <?php echo get_field('course_language', $post->ID) ?></span>, 
                          <span class="timezone">Time zone: <?php echo get_field('course_timezone', $post->ID) ?></span>
                          <?php endif; ?>
    
                          <div class="map-modal">
                            <div class="map-container">
                              <h2><?php echo get_field('full_address') ?></h2>
                              <a class="close-map">X</a>
                              <?php 
    
                              $location = get_field('location');
    
                              if( !empty($location) ):
                              ?>
                                <div class="acf-map">
                                  <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
                                </div>
                              <?php endif; ?>
                            </div>
                            </div>
                        </span>
    
                        <?php $soldout = get_field('sold_out', $post->ID); $closed = get_field('waiting_list', $post->ID);
    
                          if (($soldout) && ($closed == false)) : ?>
    
                          <p class="waiting-list">To join the waiting list, please contact <a href="mailto:training@romanpichler.com">training@romanpichler.com</a></p>
    
                          <?php elseif (($soldout) && ($closed)) : ?>
    
                          <p class="waiting-list">The waiting list is now full - thank you for your interest, and keep an eye out for future dates!</a></p>
    
                          <?php else : ?>
    
                        <?php endif; ?>
    
                      </div>
                      <div class="course-actions">
    
                        <?php $has_eventbrite = get_field('eventbrite', $post->ID); 
                      
                        if ($has_eventbrite) : ?>
    
                          <button class="cta primary active">
    
                            <?php $soldout = get_field('sold_out', $post->ID);
                            
                            if ($soldout == false) : ?>
    
                            Register
    
                            <?php else : ?>
    
                            Sold Out
    
                            <?php endif; ?>
                          
                          </button>
    
                        <?php else : ?>
    
                          <a href="<?php echo get_field('event_link', $post->ID); ?>" class="cta primary active" target="_blank">
                          
                            <?php $soldout = get_field('sold_out', $post->ID);
                            
                            if ($soldout == false) : ?>
    
                            Register
    
                            <?php else : ?>
    
                            Sold Out
    
                            <?php endif; ?>
                        
                        </a>
    
                        <?php endif; ?>
    
                      </div>
    
                      <?php $has_eventbrite = get_field('eventbrite', $post->ID); 
                      
                        if ($has_eventbrite) : ?>
    
                        <div class="eventbrite-iframe">
                          <?php echo tribe_eb_event() ?>
                        </div>
    
                      <?php endif; ?>
    
                    </div>
    
                   <?php } ?>
    
                   <?php wp_reset_postdata() ?>
    
                   </div>
    

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Masood

    (@masoodak)

    Hi @rocketmatt,

    Thanks for reaching out!

    Since you are using tribe_get_events to fetch events, you could place a simple PHP conditional to check if $events variable is empty or not. If empty, it would mean that there are no events available and in that case, echo a message at the frontend.

    Hope this helps.

    Kind regards,
    Masood

    Plugin Support Jaime

    (@jaimemarchwinski)

    Hey there! This thread has been inactive for a while so we’re going to go ahead and mark it Resolved. Please feel free to open a new thread if any other questions come up and we’d be happy to help. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.