Get list of term names in single line of code
-
Right now I’m doing something like this:
$town_array = get_the_terms($post->ID, ‘town-name’);
foreach $town_array as $town_single {
$town_name_array[] = $town_single->name;
}
$town_names_string = implode(“,”, $town_name_array);Is there a way to reduce that to a single line? There must be, but I can’t seem to make it happen. This is primarily a mental exercise, though there is a situation where I’d like to use it.
Thanks in advance!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Get list of term names in single line of code’ is closed to new replies.