Используйте это в цикле get_the_category($id)
Чтобы сделать это вручную (т. Е. Создав свою собственную функцию), добавьте это в функцию и вызывайте, когда вам это нужно
<ul>
<?php $the_query = new WP_Query( 'posts_per_page=5' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php get_the_category(the_ID())->name; // caetgory name ?></li>
<?php
endwhile;
wp_reset_postdata();
?>
</ul>