Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PHP: WordPress return top most parent ID
* [Gets the top most parent of a post. If post is top most parent, returns ID]
* @return int [ID of top most parent]
function get_earliest_relative($post){
if ($post->post_parent){
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
return $parent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.