Created
April 28, 2014 09:10
-
-
Save soutar/11366293 to your computer and use it in GitHub Desktop.
Return the ultimate ancestor of a post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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