Trying to make posts that are in the past compared to ACF the_field('end_date')

Current code:

$loop = new WP_Query( array(
    'category_name' => 'gold',
    'meta_key'    => 'status',
    'meta_value'  => 'active',
    'orderby'   => 'rand',
    'posts_per_page' => -1,
    'relation' => 'AND',
        'key' => 'end_date',
        'value' => date("y-m-d"),
        'compare' => '>=',
        'type' => "DATE"

You seem to be missing the meta_query proprety and looking at your code you seem to have two meta values mixed, so we need to combine them.

$loop = new WP_Query([
    'category_name'  => 'gold',
    'orderby'        => 'rand',
    'posts_per_page' => -1,
    'meta_query' => [
        'relation' => 'and',
            'key'   => 'status',
            'value' => 'active'
            'key'     => 'end_date',
            'value'   => date('Y-m-d'),
            'compare' => '>=',
            'type'    => 'DATE'

Also date('y-m-d') return the current date (if we go by the date this answer was creates it will return 21-10-14), that is not a valid date format you this compare will not work.
Even if it was are looking for posts that are equal or older then the current date, which, I assume is not correct (I cound be wrong so feel free to correct me on that =]).

You need to make sure that you have stored a valide date format in that meta field, needs to be date('Y-m-d') instead of date('y-m-d'), notice the upper case Y.

  • Woop! Yes! That did the trick! I dont have enough reputation, any viewers please upvote. Oct 14 at 19:14

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.