如果为空或未设置,则目标POST_DATE_GMT

时间:2019-11-08 作者:DevSem

所以我试图将一些帖子纳入我的功能中,但我似乎无法让它发挥作用。

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);
然后我得到如下一个结果:

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)
在我的OR查询中,如何确定post\\u date\\u gmt的目标?我试过了compare == null, value = \'\' 而我似乎仍然无法瞄准它。

以下是完整代码:

$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 个回复
SO网友:DevSem

我已经弄明白了:

\'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\',
            ),
        )
    ),
),