我正在尝试查询两种自定义帖子类型-我想要全部research_article
返回,但仅限于events
那是未来的事。我的活动按预期进行,但我没有收到任何research\\u文章的帖子。这里怎么了?
$today = date( \'Y-m-d\' );
$args = array(
\'post_type\' => array(\'research_article\', \'events\'),
\'meta_key\' => \'wpcf-date_time\',
\'post_status\' => \'publish\',
\'orderby\' => \'meta_value\',
\'order\' => \'DESC\',
\'meta_query\' => array(
array( // THIS ONE WORKS
\'key\' => \'wpcf-date_time\',
\'value\' => $today,
\'compare\' => \'>=\',
\'type\' => \'DATE\',
),
array(
\'key\' => \'pub_date\', // THIS DOESNT WORK
\'compare\' => \'EXISTS\'
),
\'relation\' => \'OR\',
)
);
最合适的回答,由SO网友:Rainy 整理而成
因此,问题似乎出在我的第二个meta\\u查询数组上——我没有检查pub\\u date是否存在,而是决定检查wpcf date time是否不存在:
$today = date( \'Y-m-d\' );
$args = array(
\'post_type\' => array(\'research_article\', \'events\'),
\'posts_per_page\' => 10,
\'post_status\' => \'publish\',
\'orderby\' => \'meta_value date\',
\'order\' => \'DESC\',
\'meta_query\' => array(
array(
\'key\' => \'wpcf-date_time\',
\'value\' => $today,
\'compare\' => \'>=\',
\'type\' => \'DATE\',
),
array(
\'key\' => \'wpcf-date_time\',
\'compare\' => \'NOT EXISTS\'
),
\'relation\' => \'OR\',
)
);