• Resolved rftbdev

    (@rftbdev)


    The following code will output events in an ascending manner, but it will also retrieve past events.

    <?php
                    
      $args = array(
      'post_type' => 'event',
      'posts_per_page' => -1,
      'meta_key' => '_event_start_date',
      'orderby' => '_event_start_date',
      'order' => 'ASC',
      );
    
      $posts = get_posts($args);
      $chunked = array_chunk($posts, 6, false);
    
      foreach ($chunked as $chunk) :
        get_template_part('template-parts/grids/events-grid', null, [
        'posts' => $chunk,]);
      endforeach;
    
      wp_reset_postdata();
    ?>

    I only want to show events that are in the scope ‘future.’ Unfortunately, it appears that you cannot pass the ‘scope’ in the $args array to the WP_Query (in my case get_posts())

    With that being said, I tried to use ‘compare’ => ‘>=’ against a ‘value’ => $today

    
    $today = date('Y-m-d'); (this is the format of the date in the database)
    
    $args = array(
      'post_type' => 'event',
      'posts_per_page' => -1,
      'meta_key' => '_event_start_date',
      'orderby' => '_event_start_date',
      'order' => 'ASC',
      // 'meta_value' => $today, (this format will not retrieve any posts)
      'value' => $today, (this format will not filter events greater than or equal to 
       today)
      'compare' => '>=',
    );

    Any help is much appreciated.

    The goal is to query all future/upcoming events, to exclude past events.

    • This topic was modified 2 years ago by rftbdev.
Viewing 6 replies - 1 through 6 (of 6 total)
  • bojates

    (@bojates)

    This isn’t a direct answer to your question, but might help. I guess there’s a reason you’re not using this, but just in case you missed it, you can do this:

    echo EM_Events::output(array('scope'=>'tomorrow', 'limit'=>10, 'pagination'=>1));

    And obviously don’t need to echo that, but can manipulate as necessary.

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

    • This reply was modified 2 years ago by bojates.
    Thread Starter rftbdev

    (@rftbdev)

    Thank you bojates. This definitely gets me somewhere. I appreciate your feedback!!

    Thread Starter rftbdev

    (@rftbdev)

    I need to return an array not a string. I am trying to print the returned value to discern what will be used as the separator for the explode() function

    $posts = EM_Events::get(array(‘scope’=>’future’), false); ?

    • This reply was modified 2 years ago by rftbdev.
    Thread Starter rftbdev

    (@rftbdev)

    THANK YOU bojates! ?? HAPPY CODING!

    Thread Starter rftbdev

    (@rftbdev)

    SOLVED @bojates

    bojates

    (@bojates)

    Ace ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WP_Query ONLY Future Posts’ is closed to new replies.