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

  • stitox

    (@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

    (@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
    }

    stitox

    (@stitox)

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

    stitox

    (@stitox)

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

    JohnC28

    (@johnc28)

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

    get_page

    Michael

    (@alchymyth)

    Forum Moderator

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

    $page_id = $post->ID

    there might be some ideas in here: http://wordpress.org/support/topic/link-to-parent-page?replies=12

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