Listing a post’s categories and subcategories

Update 1:

Thanks to @birgire for suggesting a better way:

wp_list_categories( [ 'include' => wp_list_pluck( get_the_category(), 'term_id' ) ] );

Try this in your single.php template:

$current_cats = get_the_category();
$current_cats_ids = [];

foreach ($current_cats as $cat) {
    $current_cats_ids[] = $cat->term_id;
}

wp_list_categories([
    'include' => $current_cats_ids,
]);

Leave a Comment