WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a query as follows:

$wp_query = new WP_Query( 
   'meta_key'     => 'end_date', 
   'meta_value'   => 'today', 
   'meta_compare' => '>=', 
   'post_type'    => 'vehicle' 

I want to show only those posts of the vehicle post type that have the meta key end_date which contains a date that is later than today's date.

How can this be accomplished?

share|improve this question
up vote 9 down vote accepted

First, your date format has to be in descending order from largest to smallest units, i.e.: year, month, day, hour, minute, second, etc., otherwise MySQL can't query or order on the field. In this example I use year - month - day:

$today = date( 'Y-m-d' );
$args = array(
    'post_type' => 'vehicle',
    'meta_query' => array(
            'key' => 'end_date',
            'value' => $today,
            'compare' => '>=',
            'type' => 'DATE'
$query = new WP_Query( $args );
share|improve this answer
+1 Btw: If a question is good enough to answer, than it should also be good enough to upvote it. Related question and drop by in chat some day :) – kaiser Jul 10 '12 at 5:20

WordPress added Date Queries in 3.7. So you could always try:

$today = date( 'Y-m-d' );
$args = array(
    'post_type' => 'vehicle',
    'date_query' => array(
        //set date ranges with strings!
        'after' => 'today',
        //allow exact matches to be returned
        'inclusive'         => true,
$query = new WP_Query( $args );

More on this can be found at https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.