get_ancestors()
returns an array containing the parents of any given object.
This example has two categories. The parent with the id of 447 and the child with a id of 448 and returns the a category hierarchy (with IDs):
get_ancestors( 448, 'category' );
returns:
Array
(
[0] => 447
)