I am trying to print the selected taxonomies related to the posts in an archive page. I’ve got thr following code but this produces duplicates due to it literally displlaying the category of each post in turn.

See attached image Screenshot of the results

How can I ensure each category only displays once ?

$categories_lists = array();
$category = array();
while ( have_posts() ) : the_post();
    $categories_lists[] = get_the_term_list( $post->ID, 'dt_portfolio_category', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );

foreach($categories_lists as $result)
   $category[] = $result;
$unique = array_unique($category);

foreach($category as $cats)
   echo $cats;


Any help is appreciated.

Read more here: Display taxonomies without duplicates [on hold]


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: