Display taxonomies without duplicates [on hold]

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 ?

<?php 
$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>' );
endwhile;


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]

Leave a Reply

Your email address will not be published. Required fields are marked *