Created
April 30, 2016 23:40
-
-
Save mrfoxtalbot/574c590559213682928325347c7884b0 to your computer and use it in GitHub Desktop.
Get top level ancestor in hierarchical post
This file contains 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
function get_topmost_parent($post_id){ | |
$parent_id = get_post($post_id)->post_parent; | |
if($parent_id == 0){ | |
return $post_id; | |
}else{ | |
return get_topmost_parent($parent_id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment