0
votes

I'm trying to setup a custom post type page 'events' which lists out upcoming events and past events. The date for the event is stored in a custom field using (Advanced Custom Fields) plugin. Now I'm trying to use a WP_Query and loop through all posts that have there custom field date (event_date) set to after the current date. Any help on how I could achived this?

My effort below. thanks

$today = date('yyyy-mm-dd');
$args  = array(
'meta_query' => array(
    array(
    'key' => '_acf_event_date',
    'value' => ''.$today.'',
    'type' => 'date',
    'compare' => '>' 
  )
),
'post_type' => array(
    'events'
),
'posts_per_page' => -1,
'paged' => get_query_var('paged')

);
$query = new WP_Query($args);

loop

ideas?

1
how are your dates stored in the database? look in the post_meta table - RRikesh
Thanks for the idea to check how it was saving it to the database. I've now matched the format and its working. - invamped

1 Answers

2
votes

Thanks to @RRikesh who point me to look at the database and see what format it was getting saved as. Turns out I was comparing to incorrect formats.

changed too.

'meta_query' => array(
    array(
    'key' => 'event_date',
    'value' => date('Y-m-d'),
    'type' => 'date',
    'compare' => '<='

  )

thanks