If you want to show a term and all its parents/ancestors, you can do the following:
function display_term_parents( \WP_Term $starting_term ) {
$terms = [];
$term = $starting_term;
while ( !is_wp_error( $term ) ) {
$terms[] = $term->name;
$term = get_term( $term->parent, 'kernal_category' );
}
$terms = array_reverse( $terms );
echo implode(' > ', $terms );
}
Where $starting_term
is the term you want to show the ancestors/parents for.
This can be done for each term ( or just the first term ) that a post has, assuming that you’ve only checked the term you want, but not all of its parents too