Support » Fixing WordPress » how to get the ID the page parent

  • stitox


    HI everybody,
    I wanna test if a page has a parent and how can i get the name and id of that parent and thanks a lot 😛

Viewing 5 replies - 1 through 5 (of 5 total)
  • JohnC28


    This should do it:

    $page_id = 1; //replace with whatever page id you want to check
    $page_data = get_page( $page_id );
    $parent_id = $page_data->post_parent; // Get Parent
    if( $parent_id != null) {
    $page_data = get_page( $parent_id );
    $title = $page_data->post_title; // Get Parent title



    wonderful answer,i just now need the name of the page.that’s what i really need and thanks a lot



    I know just how to get the post id but how could we get the page Id? i’m in a real problem 🙁



    This page tells you everything you get back – I think your answer is in there.




    Forum Moderator

    generally, in pages, it is the same as in posts:

    $page_id = $post->ID

    there might be some ideas in here:

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to get the ID the page parent’ is closed to new replies.