Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I identify that a page is a grandchild page?

share|improve this question

1 Answer 1

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.

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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