I want category name with these post name by custom post type.
Example:
Category Name: Birds
Post Name: Peacock
Category Name: Cities
Post Name: Jaipur
I want category name with these post name by custom post type.
Example:
Category Name: Birds
Post Name: Peacock
Category Name: Cities
Post Name: Jaipur
Solved.
The answer is: polling-cat is name of taxanomy name of custom post type.
$terms = get_terms( 'polling-cat' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
echo $term->name;
$args = array(
'posts_per_page' => 5,
'polling-cat' => $term->slug,
'post_type' => 'polling',
'post_status' => 'publish',
);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );
the_title();
endforeach;
wp_reset_postdata();
}
}