这看起来很简单,我有一个循环,可以从中加载帖子,包括当前帖子。
<?php
$categories = get_the_category();
foreach( $categories as $category ) {
$catID[] = $category->cat_ID;
}
$args = array(
\'category__in\' = > $catID,
\'category__not_in\' = > 1,
\'posts_per_page\' = > 10,
\'date_query\' = > array(
array(
\'before\' = > get_the_date()
),
\'inclusive\' = > true,
)
);
$loop = new WP_Query($args);
while ($loop -> have_posts()) {
$loop -> the_post();
get_template_part( \'sidebar-posts-template\' );
}
wp_reset_postdata();
?>
问题是它没有include 当前职位。为什么?编辑:这个循环使用固定日期也不起作用,将从27日开始加载帖子,不包括28日。这个inclusive
日期应包括28日起的帖子。
$args = array(
\'date_query\' = > array(
array(
\'after\' = > \'January 1st, 2013\',
\'before\' = > array(
\'year\' = > 2013,
\'month\' = > 2,
\'day\' = > 28,
),
\'inclusive\' = > true,
),
),
\'posts_per_page\' = > -1, );
编辑2:这是我现在使用的循环。$args = array(
\'category__in\' => $catID,
\'category__not_in\' => 1,
\'posts_per_page\'=>10,
\'date_query\' => array(
array(
\'before\' => get_the_date(),
\'inclusive\' => true,
),
)
);
编辑3:$args = array(
\'posts_per_page\'=>10,
\'date_query\' => array(
array(
\'before\' => array(
\'year\' => 2013,
\'month\' => 2,
\'day\' => 28,
),
\'inclusive\' => true
),
)
);