查询自定义元值-发布视图和日期元

时间:2017-04-14 作者:Sadia Mehjabin

我正在制作我的第一个后视图计数器。我已将视图存储在post-view 元数据和最新日期元数据post_view_last. 现在我想展示过去7天、30天的帖子。我对过去7天的查询如下,但没有显示帖子。基本原理-

过去7天的查询帖子post_view_lastpost-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\'
  )));

1 个回复
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
            )
        )
);

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post