Category Archive, list subcategories of each post

If you want to list only child categories of the current category, set the child_of argument to the current category ID.

wp_list_categories(
    array(
        'child_of' => get_queried_object_id(), // this will be ID of current category in a category archive
        'style' => 'none',
        'title_li' => ''
    )
);

EDIT- To list only child categories per-post of the current category, you’ll need to filter the list of each post’s terms to check that parent is the current category ID.

$terms = get_the_terms( get_the_ID(), 'category' );

if( $terms && ! is_wp_error( $terms ) ){
    echo '<ul>';
    foreach( $terms as $term ) {
        if( get_queried_object_id() == $term->parent ){
            echo '<li><a href="' . get_term_link( $term ) . '">' . $term->name . '</a></li>';
        }
    }
    echo '</ul>';
}

Leave a Comment