0

So I'm trying to target some posts to include in my function but I just can't seem to get it to work.

When I have the meta_query taken out I get 9 results (Works):

$args = array(
    'post_type'      => 'office',
    'post_status'    => 'any',
    'posts_per_page' => -1,
    'date_query' => array(
        array(
            'column' => 'post_modified_gmt',
            'before' => $started,
        ),
    ),
);
$the_query = new WP_Query($args);

Then I get one result as below:

object(WP_Post)[1306]
  public 'ID' => int 50794
  public 'post_author' => string '16' (length=2)
  public 'post_date' => string '2017-10-10 17:24:03' (length=19)
  public 'post_date_gmt' => string '0000-00-00 00:00:00' (length=19)

In my OR query, how can I target the post_date_gmt? I've tried compare == null, value = '' and I still can't seem to target it.

Here is the full code:

$args = array(
    'post_type'      => 'office',
    'post_status'    => 'any',
    'posts_per_page' => -1,
    'date_query' => array(
        array(
            'column' => 'post_modified_gmt',
            'before' => $started,
        ),
    ),
    'meta_query' => array(
        array(
            'relation' => 'OR',
            array(
                'key' => '_setting_update',
                'value' => '1',
                'compare' => '=='
            ),
            array(
                'key' => 'post_date_gmt',
                'value' => '',
                'compare' => '==',
            ),
        ),
    ),
);
$the_query = new WP_Query($args);
1

I've figured it out:

'meta_query' => array(
    array(
        'relation' => 'OR',
        array(
            'key' => '_setting_update',
            'value' => '1',
            'compare' => '=='
        ),
        array(
            'relation' => 'AND',
            array(
                'key' => '_created_date',
                'value' => '',
                'compare' => 'NOT EXISTS',
            ),
            array(
                'key' => '_modified_date',
                'value' => '',
                'compare' => 'NOT EXISTS',
            ),
        )
    ),
),

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.