最终这样做(例如,如果相关帖子的ID为5):
function filter_posts($query) {
if ( $query->is_category() && $query->is_main_query()) {
$this_category = get_queried_object();
if (0 == $this_category->parent) // Category has no parent
$query->set(\'post__not_in\', array(\'5\'));
}
}
add_action(\'pre_get_posts\', \'filter_posts\');