I have the same problem.
I have written a function that resolves the problem. It's not perfect, because it sends multiple requests to find post parent, so I am afraid it's quite slow, but anyway it works.
function get_ancestors ($id) {
$p = get_post ($id);
$parent = $p->post_parent;
$ancestors = array ();
while ($parent != '0') {
$ancestors[] = $parent;
$p = get_post ($parent);
$parent = $p->post_parent;
}
return $ancestors;
}
You can put the function into your plugin file, or functions.php of your template file and use it like:
$ancestors = get_ancestors (post_id)
where post_id is the id of the post of course ;)
Hope this helps:)
Edit:
After a while I realized you can also pass whole $post as an argument - and shorten everything by one request. The code will look like:
function get_ancestors ($p) {
$parent = $p->post_parent;
$ancestors = array ();
while ($parent != '0') {
$ancestors[] = $parent;
$p = get_post ($parent);
$parent = $p->post_parent;
}
return $ancestors;
}
And usage: $ancestors = get_ancestors ($post)