How to check whether a page is a direct or indirect child page of another page in WordPress?

I have a page with id 63. That page is having a number of child pages and each of the child pages is again having sub pages. In short page with id 63 is super parent to all the pages.

What I want is, I want to check whether the current page is a child of page with id 63. Either a direct child/child of child up to any level.

Read More

I am able to check the whether the page is a child of page 63. But not able to check the same for child of child pages.

I am using $post->post_parent == 63 to check whether the page is a child of page 63.

How can I check the same for all levels of pages ?

Related posts

Leave a Reply

2 comments

  1.     $pageId= get_the_ID(); 
        function get_topmost_parent($post_id)
        {
            $parent_id = get_post($post_id)->post_parent;
            if($parent_id == 0)
            {
                return $post_id;
            }
            else
            {
                return get_topmost_parent($parent_id);
            }
        }