$term = implode(',', array_map(function($o) { return $o->term_id; }, $array));
Или:
$term = array();
foreach($array as $o) $term[] = $o->term_id;
$term = implode(',', $term);
В функции:
function getTerms($array) {
$term = array();
foreach($array as $o) $term[] = $o->term_id;
return implode(',', $term);
}