'Shortcode Loop Custom Post Type - get the title of category

I made a shortcode to loop through a special category. I did this with an attribute in the shortcode, where you can just add your category slug. Everything works fine.

What I don´t know is how to get the title of the category to add this before the loop as the headline for this shortcode.

Do you have any tips for me how to solve this?

See my code in my functions.php below:

function speisekarte_shortcode($attr)
{
    
    $shortcode_args = shortcode_atts(
    array(
            'kategorie'     => ''
    ), $attr); 

    $args = array(
        'tax_query' => array(
            array(
                'taxonomy' => 'speisekarte_kategorie', // This is the taxonomy's slug!
                'field' => 'slug',
                'terms' => $shortcode_args['kategorie']
            )
        ),
        'orderby'           => 'asc',
        'posts_per_page'    => '-1',
        'post_type'         => 'speisekarte',
        'post_status'       => array( 'publish' )
    );

    $loop = new WP_Query($args);

    ob_start(); ?>
    
    <?php
    while ($loop->have_posts()) : $loop->the_post();
    $post_id = get_the_ID();
    ?>
        <div class="speisekarte-eintrag">
            <?php the_title();?>
            <?php the_field('beschreibung');?>         
            <?php the_field('preis');?>  
        </div>       
    <?php
    endwhile; ?>

    <?php

    wp_reset_postdata();

    // return buffer
    return ob_get_clean();

    
}  

add_shortcode( 'speisekarte', 'speisekarte_shortcode' );


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source