正在尝试从DATE_QUERY中排除粘滞帖子

时间:2014-12-09 作者:Melissa Spiegel
<?php
$lastThirty = date(\'Y-m-d\', strtotime(\'today - 30 days\'));
$currentMonth = date(\'M Y\'); 
$t = date(\'d-m-Y\');
$today = date("D",strtotime($t));

$lastThirty = array(
    \'date_query\' => array(
        \'post__not_in\' => get_option( \'sticky_posts\' ),
          \'ignore_sticky_posts\' => false,
        array(
            \'year\'  => $lastThirty,
            \'month\' => $currentMonth,
            \'day\'   => $today,

            \'orderby\' => \'date\',
            \'order\' => \'DESC\'
        ),
    ),
); ?>

<?php
$the_query = new WP_Query($lastThirty);


?>
1 个回复
SO网友:skim-

设置查询时,请这样做(我认为您缺少“date\\u query”键):

$args = array(
    \'date_query\' => array(
        array(
            \'year\'  => 2012,
            \'month\' => 12,
            \'day\'   => 12,
        ),
    ),
    \'ignore_sticky_posts\' => true,
    \'post__not_in\'  => get_option(\'sticky_posts\') ...
);
$query = new WP_Query( $args );

http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters

结束

相关推荐

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

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