I’ve got a custom taxonomy called “Artists”. I’d like to be able to display the artists as follows:
[Main Artist / First in Array] ft. [Second Artists], [Third Artist] & [Last Artist]
The code I’m currently using to display the “Artist” is:
<?php $artists_links = get_the_term_list( $track->ID, 'artists', '', ' ', '' );
$artists_withoutlinks = strip_tags( $artists_links );
echo $artists_withoutlinks ?>
So would anyone be able to help with this? In summary all I want to be able to do is:
- Change the separator after the first term to “ft.”
- Change the separator before the last term to “&”
Obviously I want to keep database calls to a minimum, and make the query as fast as possible, any help is greatly appreciated.
Use
get_the_terms()instead ofget_the_term_list(). While the latter fetches the terms into a string, the first creates an array of terms. Still only one query. Create the string from the array afterwards: