Hay, how would i find out if a page is a grand child?

Thanks

link|improve this question

75% accept rate
feedback

1 Answer

up vote 1 down vote accepted

use get_page twice like this handy little function

function get_grandpapa($page_id){
    $current_page = get_page( $page_id );
    if ($current_page->post_parent > 0){
        //has at least a parent
        $parent_page = get_page($current_page->post_parent);
        if ($parent_page->post_parent > 0){
            return $parent_page->post_parent;
        }else{
            return false;
        }
    }
    return false;
}

This function returns the grandparent page ID or false if there is no grandparent.

link|improve this answer
Why thank you! I had to Booleanate the function (renamed to is_grandchild) and changed line 7 to "return true". – dotty Mar 10 '11 at 14:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.