guillermorangel
1/5/2015 - 11:15 PM

Get the top parent id http://www.webcitizenmag.com/2010/05/20/how-to-get-top-parent-page-id-in-wordpress/

<?php

function get_top_parent_page_id() {
 
    global $post;
 
    $ancestors = $post->ancestors;
 
    // Check if page is a child page (any level)
    if ($ancestors) {
 
        //  Grab the ID of top-level page from the tree
        return end($ancestors);
 
    } else {
 
        // Page is the top level, so use it's own id
        return $post->ID;
 
    }
 
}

?>