The following code takes the absolute child tid and grabs all parents. The second argument is for the amount of terms you wish to return; and the thrid for how you want to order it.
/**
* @file Orders Taxonomy
*
* @param $output - expecting a tid // check this at the point of running the function
* @param $no_results - the number of results that you'd like to return
* @param $order - which tid first - child or most senior parent ?
*/
function taxonomy_order($output, $no_results = 1, $order = 'first') {
$terms = entity_load('taxonomy_term', array($output));
$wrapper = entity_metadata_wrapper('taxonomy_term', $output);
$all_parents = $wrapper->parents_all->value();
( $order == 'last' ) ? $all_parents = array_reverse($all_parents) : $all_parents;
$stitch_term_array = '';
foreach ($all_parents as $key => $term) {
($key < $no_results ) ? $stitch_term_array .= $term->name . ", " : '';
}
$stitch_term_array = rtrim($stitch_term_array, ', ');
return $stitch_term_array;