0

I would like to get WordPress posts whose custom field date is in the future, but I have a problem getting correct results from this query:

$args = array( 
    'posts_per_page' => -1, 
    'post_type'      => 'matches',
    'meta_key'       => 'date',
    'compare'        => '>=',
    'meta_value'     => '2016-11-12',
    'type'           => 'DATE'
);

All I get are posts where the date matches '2016-11-12', though I use 'compare' => '>=', and even 'compare' => '>', shows these very same results. I don't understand that at all!

  • 1
    There is no argument named compare outside of a meta_query, it is meta_compare. – Milo Nov 10 '16 at 15:47
  • @Milo as an answer please :) – Rarst Nov 10 '16 at 17:03
1

There is an argument meta_compare. Use it for comparison.

$args = array( 
    'posts_per_page' => -1, 
    'post_type'      => 'matches',
    'meta_key'       => 'date',
    'meta_compare'   => '>',
    'meta_value'     => '2016-11-12',
    'type'           => 'DATE'
);

Your Answer

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

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