啊哈,我想这是个拼写错误。
没有调用任何参数posts__not_in
. 它叫post__not_in
.
因此,您应该将代码更改为:
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 );
}