I have the below code to list the Array of terms
, I am placing a comma between the terms if there are more than one term
assigned to the post.
$terms = get_terms('my_term', $args);
if (!empty($terms) && !is_wp_error($terms)) {
$count = count($terms);
$i = 0;
$term_list = '<span>';
foreach ($terms as $term) {
$i++;
$term_list .= '#<a href="' . esc_url(get_term_link($term)) . '"><span>' . $term->name . '</span></a>';
if ($count != $i) {
$term_list .= ', ';
} else {
$term_list .= '</span>';
}
}
}
Now, I would like place a &
between the last two terms instead of a ,
if there are more than one term assigned to the post.