Getting Post ID’s for Current page, Parent, and Grand Parents

// current page (ID)
$currentpage = $post->ID;
// immediate parent page id
$parentpage = $post->post_parent;
// get all parents and grand parents in an array
$grandparent = get_post_ancestors($currentpage);
// grand parent page id = From the array created above
$grandparentID = $grandparent[1];
// echo out your new array if you want to see
echo "<pre>"; print_r($parent); echo "</pre>";

 

One thought on “Getting Post ID’s for Current page, Parent, and Grand Parents

Leave a Reply

Your email address will not be published. Required fields are marked *

54 − = 52