• Resolved calidewberry

    (@calidewberry)


    I am trying to call only future events in a loop but strange things are happening. Different things happen with different categories and this loop works correctly with some categories and not others. I have two categories, ‘workshops’ and ‘third-party-events’ Here is my code, any help will be much appreciated.

    <?php $loop = new WP_Query(array(
        'post_type' => 'event',
        'event-categories'=> 'workshops',
        'orderby' => 'meta_value', // We want to organize the events by date 
        'meta_key' => '_event_start_date', // Grab the "start date" field created via "More Fields" plugin (stored in YYYY-MM-DD format)
        'posts_per_page' => 20,
         'order' => 'ASC',
        'meta_query' => array( // WordPress has all the results, now, return only the events after today's date
            array(
                'key' => '_event_start_date', // Check the start date field
                'value' => date("d-m-Y"), // Set today's date (note the similar format)
                'compare' => '>=', // Return the ones greater than or equal to today's date
                'type' => 'DATE' // Let WordPress know we're working with date
                ) )
                )); 
              ?>
    
    <div class="container event-col-container">
     <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>   
         <?php if ( has_post_thumbnail() ) { ?>  
      <!-- Start Columns -->
        <div class="event-in-cols">
               <div class="event-col">
                   <p><?php the_date(); ?></p>
                   
                    <div class="event-col-img">
                        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'full' ); ?></a>        
                    </div>
                    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>     
                </div>
        </div><!-- /Columns -->  
      <?php } ?>
    <?php  endwhile; wp_reset_postdata(); ?>  
    </div>  
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    With the output and attributes you want. I think it would be better to just use a combination of shortcodes and placeholders.

    https://wp-events-plugin.com/documentation/shortcodes/
    https://wp-events-plugin.com/documentation/placeholders/
    https://wp-events-plugin.com/documentation/event-search-attributes/

    You could event wrap the placeholders on html tags. I would suggest checking the scope attribute also which lets you specify if you want to get the past, future events.

    Thread Starter calidewberry

    (@calidewberry)

    Thank you for your reply, I had seen that, I am pretty new at this, but have implemented your suggestion. The only problem is that the loop keeps repeating on the first loop on the same page and I don’t know how to stop this loop. I have tried both class_exists and !empty but i cant seem to end the if without getting a blank screen.

    
    <!-- TAB TEST --> 
    <div class="tabs">
        <ul class="tab-links">
            <li class="active"><a href="#tab1">EVENTS</a></li>
            <li><a href="#tab2">WORKSHOPS</a></li>
    
        </ul>
    
        <div class="tab-content">
        <!-- Third Party Events -->     
            <div id="tab1" class="tab active">
                <article>
                    <div class="container">
                        <h2>Upcoming Events</h2>
                        <div id="events-page-banner">
                            <div class="container event-col-container">
                                <?php if (!empty('EM_Events')) {
                                echo EM_Events::output(array('scope'=>'future','category'=> 'third-party-events', 'limit'=>10, 'format'=>' 
                                  <!-- Single Events -->
                                    <div class="event-in-cols">
                                           <div class="event-col">
                                               <p>#_EVENTDATES</p>
                                                <div class="event-col-img">
                                                    <a href="#_EVENTURL">#_EVENTIMAGE</a>        
                                                </div>
                                                <h3><a href="#_EVENTURL">#_EVENTNAME</a></h3> 
                                                <p>#_CATEGORYNAME</p>
                                            </div>
                                    </div><!-- /Single Event -->
                                '));
                                } 
                                ?>
                                
                            </div> 
                        </div>                
                    </div>    
                </article>
            </div>
    
        <!-- Workshops -->     
            <div id="tab2" class="tab active">
                <article>
                    <div class="container">
                        <h2>Upcoming Workshops</h2>
    
                        <div id="events-page-banner">
                            <div class="container event-col-container">
                                <?php if (class_exists('EM_Events')) {
                                echo EM_Events::output(array('scope'=>'future','category'=> 'workshops', 'limit'=>10, 'format'=>' 
                                  <!-- Single Events -->
                                    <div class="event-in-cols">
                                           <div class="event-col">
                                               <p>#_EVENTDATES</p>
                                                <div class="event-col-img">
                                                    <a href="#_EVENTURL">#_EVENTIMAGE</a>        
                                                </div>
                                                <h3><a href="#_EVENTURL">#_EVENTNAME</a></h3> 
                                                <p>#_CATEGORYNAME</p>
                                            </div>
                                    </div><!-- /Single Event -->
                                '));
                                }
                                ?>  
                            </div> 
                        </div>                
                    </div>    
                </article>
            </div>
    
        </div>
    </div> 

    Why make it so difficult for yourself? As Tim already said, just use built-in shortcodes.

    In your WP Edit Page Admin (so like a normal post):

    <h2>Upcoming Workshops</h2>
    [events_list scope="future" limit="10" category="EVENT CATEGORY ID FOR WORKSHOPS"]
    <div class="event-col">
    	<p>#_EVENTDATES</p>
    	<div class="event-col-img">
    		<a href="#_EVENTURL">#_EVENTIMAGE</a>
    	</div>
    	<h3><a href="#_EVENTURL">#_EVENTNAME</a></h3> 
    	<p>#_CATEGORYNAME</p>
    </div>
    [/events_list]
    

    Aha.. I see you are using tabs… Does NOT work! EM needs a unique url with added pagination attributed for example. Tabs prevent that.

    If you want to use tabs anyway, you need to list the events using an iframe.

    Thread Starter calidewberry

    (@calidewberry)

    THANK YOU!
    FYI: it actually does work in tabs, see below:

    
    <!-- TAB TEST --> 
    <div class="tabs">
        <ul class="tab-links">
            <li class="active"><a href="#tab1">EVENTS</a></li>
            <li><a href="#tab2">WORKSHOPS</a></li>
            <li><a href="#tab3">CALENDAR</a></li>
        </ul>
    
        <div class="tab-content">
            <div id="tab1" class="tab active">
                <article>
                   <div class="container">
                        <h2>Upcoming Events</h2>
                        <!-- QUERRY TO GET EVENT COLUMS --> 
                        <div id="events-page-banner">
                            <div class="row">
                                    <?php echo do_shortcode('
                                    [events_list scope="future" limit="10" category="third-party-events"]
                                        <div class="col-sm-6 col-md-4 col-lg-3">        
                                            <div class="event-col">
                                                <div class="event-col-img">
                                                    <a href="#_EVENTURL">#_EVENTIMAGE</a>
                                                </div>
                                                <p>#_EVENTDATES</p>
                                                <h3><a href="#_EVENTURL">#_EVENTNAME</a></h3> 
                                            </div>
                                        </div><!-- /Columns -->     
                                    [/events_list]
                                    '); ?>                                 
                            </div>
                        </div> 
    
                    </div>    
                </article>
            </div>
    
                <div id="tab2" class="tab">
                <article>
                    <div class="container">
                    <h2>Upcoming WORKSHOPS</h2>
                 <!-- QUERRY TO GET EVENT COLUMS --> 
                        <div id="events-page-banner">
                            <div class="row">
                                    <?php echo do_shortcode('
                                    [events_list scope="future" limit="10" category="workshops"]
                                        <div class="col-sm-6 col-md-4 col-lg-3">        
                                            <div class="event-col">
                                                <div class="event-col-img">
                                                    <a href="#_EVENTURL">#_EVENTIMAGE</a>
                                                </div>
                                                <p>#_EVENTDATES</p>
                                                <h3><a href="#_EVENTURL">#_EVENTNAME</a></h3> 
                                            </div>
                                        </div><!-- /Columns -->     
                                    [/events_list]
                                    '); ?>                                 
                            </div>
                        </div>   
                    </div>    
                </article>
            </div>
            
            <div id="tab3" class="tab">
                <article>
                    <div class="container calendar-display">
                        <?php echo do_shortcode('[events_calendar]'); ?>
                    </div>
                </article>
            </div>
    
        </div>
    </div>   
    
    <script>
    
        jQuery(document).ready(function() {
        jQuery('.tabs .tab-links a').on('click', function(e) {
        var currentAttrValue = jQuery(this).attr('href');
         
        jQuery('.tabs ' + currentAttrValue).show().siblings().hide();
         
        jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
         
        e.preventDefault();
        });
        });
    
    </script>
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP Event Manager WP_Query not excluding past events in loop’ is closed to new replies.