1$args = array(
2 'post_type' => 'post',
3 'posts_per_page' => 4
4 );
5 $query = new WP_Query( $args );
6
7 if( $query->have_posts() ) {
8 while( $query->have_posts() ) : $query->the_post();
9 foreach((get_the_category()) as $category) {
10 echo $category->cat_name . ' ';
11 }
12 endwhile;
13 }
14 else {
15 echo "There is no posts";
16 }
17
18 wp_reset_postdata(); ?>