Answers for "post type category name in query"

PHP
0

post type category name in query

$args = array(
        	'post_type' => 'post',
        	'posts_per_page' => 4
        );
        $query = new WP_Query( $args );

	     if( $query->have_posts() ) {
    	    while( $query->have_posts() ) : $query->the_post(); 
                foreach((get_the_category()) as $category) { 
                  echo $category->cat_name . ' '; 
                } 
        endwhile;
		} 
		else {
	    	echo "There is no posts";
	    }

	    wp_reset_postdata();   ?>
Posted by: Guest on June-07-2021

Code answers related to "post type category name in query"

Browse Popular Code Answers by Language