0

I'm making a page for past events (using Event Expresso plugin) and I'm kinda confused about the wp_query.

This one works:

$atts = array(
      'title' => NULL,
      'limit' => 100,
      'css_class' => NULL,
      'show_expired' => true,
      'month' => NULL,
      'category_slug' => NULL,
      'order_by' => 'event_start_date',
      'sort' => 'DESC',
      'date_query' => array(
          array(
              'column' => 'event_start_date',
              'before' => '1 month ago',
          ),
      ),
    );

However, this one won't work (it will still show event past May 11):

$atts = array(
      'title' => NULL,
      'limit' => 100,
      'css_class' => NULL,
      'show_expired' => true,
      'month' => NULL,
      'category_slug' => NULL,
      'order_by' => 'event_start_date',
      'sort' => 'DESC',
      'date_query' => array(
          array(
              'column' => 'event_start_date',
              'before' => '2020-05-11 23:59:59',
          ),
      ),
    );

Is there something wrong with my code?

The column 'event_start_date' returns the event date when I do print_r($post->event_start_date); inside a post loop.

I'm really confused why the 2nd code does not work.

I also tried

'before' => 'now',

and

'before' => 'today',

and its not working. :(

5
  • When I search for 'Expresso Express' I can't even find anything WordPress related, just coffee stuff. Is that a plugin of sorts? Do they have a support forum? – Tony Djukic May 11 '20 at 14:01
  • Sorry, it should be Event Expresso, thank you for pointing out. I've corrected it already. – justine0905 May 12 '20 at 2:49
  • 1
    The column field only works against the wp_posts table date columns. These are post_date, post_date_gmt, post_modified, and post_modified_gmt. – Howdy_McGee May 12 '20 at 2:53
  • 1
    event_start_date, I assume, is a meta field set on event posts by the plugin. To select against a meta field, you'd need to use a meta query, not a date query: – Pat J May 12 '20 at 3:34
  • 1
    But are you sure that your first code actually works? As far I understand you want to display posts more recent than that date, so you should use after not before. – Antonio May 12 '20 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.