0

After updating to Wordpress 4.1 I've noticed one of my more complex post queries has stopped working. It's querying from an events post type and returning posts with a standard timestamp of after today at midnight, or an end timestamp of after today at midnight (for multi-day events). Here is the query:

query_posts(
    array(
        'post_type' => 'events',
        'showposts' => -1,
        'order' => 'ASC',
        'orderby' => 'meta_value_num',
        'meta_key' => '_ecmb_datetime',
        'meta_value' => strtotime('today midnight'),
        'meta_compare' => '>=',
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => '_ecmb_datetime_end',
                'value' => strtotime('today midnight'),
                'compare' => '>='
            )
        )
    )
);

I formed this query based on this answer. I had a look at this answer but I am not using 'meta_key' => 'meta_value', and to the part where the answerer says "meta_key isn't needed if you have a meta_query arg" I'm not sure that applies in the scenerio because I do want to query both key/values.

Any help is much appreciated!!

0

I formed this query based on this answer.

I would appear this is no longer the way to do it... I reformatted the query to look like this:

query_posts(
    array(
        'post_type' => 'events',
        'showposts' => -1,
        'order' => 'ASC',
        'orderby' => 'meta_value_num',
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => '_ecmb_datetime',
                'value' => strtotime('today midnight'),
                'compare' => '>='
            ),
            array(
                'key' => '_ecmb_datetime_end',
                'value' => strtotime('today midnight'),
                'compare' => '>='
            )
        )
    )
);

Which seems to have solved the problem! If anyone has any other suggestions please feel free to share :)

  • 1
    You should stop usgin query_posts, use WP_Query instead. – cybmeta Jan 13 '15 at 20:54

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.