我正在制作我的第一个后视图计数器。我已将视图存储在post-view
元数据和最新日期元数据post_view_last
. 现在我想展示过去7天、30天的帖子。我对过去7天的查询如下,但没有显示帖子。基本原理-
过去7天的查询帖子post_view_last
根据帖子视图订购帖子post-view
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => \'3\',
\'post_status\' => \'publish\',
\'meta_key\' => \'post_view\',// say 200
\'orderby\' => \'meta_value_num\',
\'order\' => \'DSC\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'post_view_last\',//2017-04-14
\'value\' => date(\'Y-m-d\', strtotime(\'-7 days\')), //value of "order-date" custom field
\'compare\' => \'<=\', //show post less than or equal to today
\'type\' => \'CHAR\'
)));
SO网友:BlueSuiter
@Sadia请尝试一下:
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => \'3\',
\'post_status\' => \'publish\',
\'meta_key\' => \'post_view\',// say 200
\'orderby\' => \'meta_value_num\',
\'order\' => \'DSC\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'post_view_last\',//2017-04-14
\'value\' => date(\'Y-m-d\', strtotime(\'-7 days\')), //value of "order-date" custom field
\'compare\' => \'>=\', //show post less than or equal to today
)
)
);