Separator for multiple terms

If you need just the term names, fetch just the term names: use the field parameter for get_terms().

Build a comma separated list with an and between the last two items with wp_sprintf_l().

// get the term names
$term_names = get_terms( 'department', array ( 'fields' => 'names' ) );
// glue the names with comma and an 'and' between the last two
if ( ! empty ( $term_names ) )
    echo wp_sprintf_l( '%l', $term_names );

Leave a Comment