How can I add a date filter to a query on a custom date field?

I would like to modify the following query to filter out posts where the event_date is older than the current date:

<?php
$args = array (
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);

$the_query = new WP_Query ($args)
?>

Please can you advise?

Merry Christmas,

Steve.

  • salsasteve
    • Flash Drive

    OK, I found the solution by modifying it as follows:

    <?php
    $today = date('Ymd');
    $args = array (
    'post_type' => 'event',
    'meta_key' => 'event_date',
    'meta_query' => array(
    array(
    'key' => 'event_date',
    'value' => $today,
    'compare' => '>='
    )
    ),
    'orderby' => 'meta_value_num',
    'order' => 'ASC'
    );

    $the_query = new WP_Query ($args)
    ?>

    I discovered that the meta_query I was struggling with needed to be placed above the ‘orderby’ and ‘order’ parameters before it would work.

    Might be useful for someone to know?

    Regards,

    Steve.