It's seemingly simple, I have this loop which should loads posts from, and including the current post.
<?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();
?>
The problem is that it doesn't include the current post. Why?
Edit: This loop, using a fixed date also does not work and will start loading posts from the 27th, not including the 28th. The inclusive
date should include posts from the 28th.
$args = array(
'date_query' = > array(
array(
'after' = > 'January 1st, 2013',
'before' = > array(
'year' = > 2013,
'month' = > 2,
'day' = > 28,
),
'inclusive' = > true,
),
),
'posts_per_page' = > -1, );
Edit 2: This is now the loop I am using.
$args = array(
'category__in' => $catID,
'category__not_in' => 1,
'posts_per_page'=>10,
'date_query' => array(
array(
'before' => get_the_date(),
'inclusive' => true,
),
)
);
Edit 3:
$args = array(
'posts_per_page'=>10,
'date_query' => array(
array(
'before' => array(
'year' => 2013,
'month' => 2,
'day' => 28,
),
'inclusive' => true
),
)
);
inclusive
parameter inside the wrong array, which is readily apparent when you use proper code indentation.