Get events from today and onwards

June 9, 2014

The following snippet can be useful to retrieve custom post_types with custom fields such as events from today and onwards.

The best choice to use this is on the WP_Query with custom field for date_start previously added. In this example the custom field is called time_start_date.

$today = date('Y-m-d');

$args = array(

     'post_type' => $post_type,                 //post type
     'orderby' => 'meta_value',
     'meta_key' => 'time_start_date',           // date_start field
     'order' => 'ASC',
     'paged' => $paged,
     'meta_query' => array(                  
            'relation' => 'AND',
                   'key' => 'time_start_date', // date_start field
                   'value' => $today,          // from today
                   'type' => 'DATE',           // we compare the custom field
                   'compare' => '>='           // to get the element.