Skip to content

Instantly share code, notes, and snippets.

@soutar
Created April 28, 2014 09:10
Show Gist options
  • Save soutar/11366293 to your computer and use it in GitHub Desktop.
Save soutar/11366293 to your computer and use it in GitHub Desktop.
Return the ultimate ancestor of a post
<?php
/* Return the ultimate ancestor of a post */
function get_post_ancestor($postID) {
$post = get_post($postID);
if (!is_object($post)) return;
while ($post->post_parent != 0): $post = get_post($post->post_parent); endwhile;
return $post;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment