Can't figure out why this query isn't working

WordPress Event Management, Calendars & Registration Forums General Question Can't figure out why this query isn't working

This topic contains 6 replies, has 2 voices, and was last updated by  Adam Abrams 7 years, 9 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #27079

    Hi Stephen!

    I’m trying to follow up a list of the upcoming week’s events with a section called “Featured events”. Here we would list events that are further away than the coming week, but which we still want to highlight.

    To achieve this, I’ve added a “Featured” category to be used for selected events.

    After my main loop, I’ve got the following additional query – intended to grab any event in the Featured category, but which does not occur within the start and end dates of the week in question (set in the Dashboard and stored with variables $Ymd_start_date and $Ymd_end_date ).

     $featuredEvents = eo_get_events(array(
            'event-category' => 'featured',
            'event_start_after' => $Ymd_end_date,
            'group_events_by' => 'series',
           'showpastevents'=>false, //Will be deprecated, but set it to false to play it safe.
          ));
    

    The problem? It works with single-day events, but doesn’t seem to work with an event which runs multiple days.

    With the main query date range set to Apr 19-26, I’m finding that one event checked “Featured” that runs Apr 1-18 is (correctly) showing up in the main listing, so I don’t want it to also appear in that second query.

    But even though it does NOT start after the “end date” for the week… it still comes up in the Featured Events list.

    Is that clear? And why is this happening?

    Thanks!
    Adam

    Adam Abrams
    #27098

    What is the value of $Ymd_end_date. Also, what is the SQL query that is run for the featured events? Query Monitor is good for finding out the queries run on a page.

    Stephen Harris
    #27123

    Currently, $Ymd_end_date is set to “2017-04-26”.

    I added it to the second loop – you can see it here:

    http://jenispicks.com/wordpress/mailout/

    For the query, the first one on the page (edited for space) is:

    <?php
      $events = eo_get_events(array(
            'event_start_after'=> $Ymd_start_date,
            'event_start_before'=>$Ymd_end_date,
            'group_events_by' => 'series',
            'showpastevents'=>false,//Will be deprecated, but set it to false to play it safe.
         ));
    
       if( $events ){
    global $post;
    foreach( $events as $post ){
    
        $post_id = $post->ID;
    
    
    //Check if all day, set format accordingly
    $format = ( eo_is_all_day($event->ID) ? get_option('date_format') : get_option('date_format').' '.get_option('time_format') );
    
         setup_postdata($post);
         ?>
    
         <div class="mailout-event" style="width: 100%;clear: both !important;display: block;float: left;margin-bottom: 1.5em;">
    
            " title="<?php the_title_attribute(); ?>" >
    
                <?php
                    //If it has one, display the thumbnail
                    the_post_thumbnail('thumbnail', array('style'=>'display:block;float:left;padding: 0 1em 1em 0;margin: 0 1em 1em 0'));
                ?>
    

    etc.

    Then there is a wp_reset_postdata(); , and then the second query, the one that isn’t doing what I’d like:

    <?php
      $featuredEvents = eo_get_events(array(
            'event-category' => 'featured',
            'event_start_after' => $Ymd_end_date,
            'group_events_by' => 'series',
           'showpastevents'=>false, //Will be deprecated, but set it to false to play it safe.
          ));
    
       if( $featuredEvents ){
    
        echo '<h2 style="margin-bottom: 1em;">Coming soon</h2>';
    
        global $post;
        foreach( $featuredEvents as $post ){
    
        //Check if all day, set format accordingly
        $format = ( eo_is_all_day($event->ID) ? get_option('date_format') : get_option('date_format').' '.get_option('time_format') );
    
        setup_postdata($post);
    
        ?>
    
        <div class="mailout-event" style="width: 100%;clear: both !important;display: block;float: left;margin-bottom: 1.5em;">
    
            " title="<?php the_title_attribute(); ?>" >
    
                <?php
                    //If it has one, display the thumbnail
                    the_post_thumbnail('thumbnail', array('style'=>'display:block;float:left;padding: 0 1em 1em 0;margin: 0 1em 1em 1em;'));
                ?>
    
                
    

    etc. (again).

    Does that hopefully help?

    Thanks!
    adam

    Adam Abrams
    #27125

    Is it the ‘Capture’ event you think shouldnt be appearing? Because it should be: it is a recurring event which has occurrences after the 26th April and so it is included on the returned set of events which event_start_after 2017-04-26

    Stephen Harris
    #27126

    The schedule start date is stored as post meta under the key _eventorganiser_schedule_start_start which you could do a meta query for (and exclude events for which the first date is before the specified date)

    Stephen Harris
    #27127

    The schedule start date is stored as post meta under the key _eventorganiser_schedule_start_start which you could do a meta query for (and exclude events for which the first date is before the specified date)

    Stephen Harris
    #27128

    Thanks so much Stephen! I was able to revise the query successfully (and learned how to do post meta comparisons – hooray for new skills!)

    Thanks,
    adam

    Adam Abrams
Viewing 7 posts - 1 through 7 (of 7 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.