John,
Thanks for your reply.
I got it to work thanks to your little code-snippet.
The only thing I changed was the populating of the array in the foreach loop:
$term_names[] = $term->name;
By adding these square brackets you ‘tell’ the array to add the new value instead of overwriting it, which is the case if you don’t add those square brackets.