WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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;
            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


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.