I am trying to get all categories of a custom post type.I am using get_the_category();
function to retrieve the categories.But if i have 3 posts with 1 category the category is repeated 3 times 😮 .
My codes are
<?php
query_posts( array( 'post_type' => 'member', 'showposts' => 8 ) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
$categories = get_the_category();
foreach ( $categories as $category ) {
echo $category->name, ' ';
}
?>
<?php endwhile; endif; wp_reset_query(); ?>
Is there any solutions??
you can find more info from Here REFERENCE FOR get_terms
Try this way get only category of custom post
You’re looping through posts, did you try this?
More info here: https://developer.wordpress.org/reference/functions/wp_list_categories/