I am trying to print the selected taxonomies related to the posts in an archive page. The below code works fine but I want to remove the duplicates.

See attached imageScreenshot of the results

How can I achieve this ?

<?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;

//$unique = array_unique($categories_lists);
//foreach()
foreach($categories_lists as $result)
{
//echo $result;
$category[] = $result;
}
$unique = array_unique($category);
foreach($category as $cats)
{
echo $cats;
}
//echo $category;
//$a = array_unique($arr);
//echo $arr;
?>

Any help is appreciated.

Read more here: Why is the below code not working?


Solution:

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: