admin管理员组文章数量:1410716
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);
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);
Share
Improve this question
asked Nov 8, 2019 at 17:11
DevSemDevSem
2092 silver badges11 bronze badges
1 Answer
Reset to default 1I'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',
),
)
),
),
本文标签: phpTarget postdategmt if it39s empty or not set
版权声明:本文标题:php - Target post_date_gmt if it's empty or not set 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745019072a2638020.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论