I have created a function to display my custom taxonomy ('market') terms. But the problem is that this outputs the first taxonomy term twice. Here is my function:
function related_markets()
{
if ('news' === get_post_type()) {
$terms = get_terms(array(
'taxonomy' => 'market',
'hide_empty' => false,
));
foreach ($terms as $term) {
$term_list .= '<a class="related-market btn btn-outline-secondary" href="' . esc_url(get_term_link($term)) . '">' . $term->name . '</a>';
echo $term_list;
}
} elseif ('analysis' === get_post_type()) {
$terms = get_terms(array(
'taxonomy' => 'market',
'hide_empty' => false,
));
foreach ($terms as $term) {
$term_list .= '<a class="related-market btn btn-outline-secondary" href="' . esc_url(get_term_link($term)) . '">' . $term->name . '</a>';
echo $term_list;
}
}
}
endif;