我尝试过基于自定义字段进行WP\\U查询,该字段的名称为“date”,值类似于“14/01/2015”。我希望查询在“日期”介于今天和明天之间时给出结果。
到目前为止,我所尝试的是:
$y=date(\'d/m/Y\',strtotime(\'yesterday\'));
$t=date(\'d/m/Y\',strtotime(\'tomorrow\'));
$o=date(\'d/m/Y\',strtotime(\'today\'));
echo "yesterday: ".$y;
echo "today: ".$o;
echo "tomorrow: ".$t;
$d=new WP_Query(
array(
\'category__in\' => array(4),
\'post_type\' => \'post\',
\'posts_per_page\' => \'-1\',
\'orderby\' => \'meta_value\',
\'order\' => \'DESC\',
\'meta_query\' => array(
\'key\' => \'data\',
\'value\' => array($y,$t),
\'compare\' => \'BETWEEN\',
\'type\' => \'DATE\',
)
)
);
但给我的帖子“日期”也是2015年1月25日。我做错了什么<谢谢你的建议
最合适的回答,由SO网友:CapitanFindus 整理而成
问题解决了,我用过这个:
$d=new WP_Query(
array(
\'category__in\' => array(4),
\'post_type\' => \'post\',
\'posts_per_page\' => \'-1\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'data\',
\'value\' => $t,
\'compare\' => \'<=\'
),
array(
\'key\' => \'data\',
\'value\' => $o,
\'compare\' => \'>=\'
)
),
)
);
而不是之前的另一个,一切都很好。