Quantcast
Channel: Question and Answer » meta-query
Viewing all articles
Browse latest Browse all 36

Meta query compare timestamp if exists

$
0
0

I have a custom post type with a start and end date timestamp. These fields are not required so they may not exist. What I want to do is query and show all posts that don’t have the end date set or that meta value is set and compare it against the current time.

The query to check if the meta field does not exist works fine, but the comparison never works. If the post has the end date set it always displays.

Here are my arguments for WP_Query:

array(
    'post_type' => 'listing',
    'posts_per_page' => 5,
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => '_event_end_date',
            'compare' => 'NOT EXISTS'
        ),
        array(
            'key' => '_event_end_date',
            'value' >= time(),
            'compare' => '>=',
            'type' => 'NUMERIC'
        )
    ),
    'orderby'   => 'title',
    'order' => 'ASC'
)

I’ve changed the compare property to ‘=’ to try and force the post with end date set to not show, but it still shows. I know the end date meta value is set, and is a valid timestamp.

Not really sure if this is a bug or if I’m not seeing something else


Viewing all articles
Browse latest Browse all 36

Trending Articles