Following function may help
// Get group name by author id (by DN 20150108)
function get_groupname_by_author_id($aid) {
global $wpdb;
$term_ids = $wpdb->get_results(
$wpdb->prepare( “
SELECT wp_term_taxonomy.term_id FROM wp_term_taxonomy
INNER JOIN wp_term_relationships USING (term_taxonomy_id)
WHERE wp_term_taxonomy.taxonomy = ‘user-group’
AND wp_term_relationships.object_id = %d
“,
$aid)
);
if($term_ids) {
$termid= $term_ids[0]->term_id;
// echo ” termid: “. $termid;
} else {
$termid=””;
}
$term = get_term_by( ‘id’, absint($termid), ‘user-group’ );
$groupname = $term->name;
if ($groupname) {
return $groupname;
} else {
$groupname = “”;
return $groupname;
}
}