Aahhh, it’s a typo, I guess.
There is no parameter called posts__not_in
. It’s called post__not_in
.
So you should change your code to:
function dark_delight_get_related_posts(){
$post = get_post();
$args = array(
'posts_per_page' => 4,
'ignore_sticky_posts' => true,
'post__not_in' => array($post->ID), // post and not posts
);
$categories = get_the_category();
if( !empty($categories) ){
$category = array_shift( $categories );
$args['tax_query'] = array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $category->term_id,
),
);
}
return new WP_Query( $args );
}