How can i get the name of a page's parent?
I can only get it's id.

        $page = get_queried_object();
        $pageparent = $page->post_parent;
  • Can you be clearer please ... a post is related to a category or tag posts are not linked to pages (pages are static and usually dont have categories or tags)
    – Damien
    Aug 25, 2012 at 8:46
  • @damien, it's a page, hierarchical one. i've edited the question, thanks
    – NestedWeb
    Aug 25, 2012 at 8:49
  • ok ill edit the question ... but have you checked the related results -----> or read up on get_pages codex.wordpress.org/Function_Reference/get_page
    – Damien
    Aug 25, 2012 at 8:53
  • i just tried with get_page, even then i can only get direct parent's and all ancestors 'id'.
    – NestedWeb
    Aug 25, 2012 at 9:00

3 Answers 3


Once you've got the id of a post or page, use get_the_title($id) to get the page title (which is what I assume you mean by name)

Codex Reference

  • Thank you, never though there's such a function.
    – NestedWeb
    Aug 25, 2012 at 13:27

Note that get_queried_object will only work on pages with a single post (or page) on them. For example, if you were trying to find a parent of a post on a category archive page, get_queried_object would return the category, not the current post.

So, using the following would work in more circumstances:

global $post;
$parent_title = get_the_title( $post->post_parent );
global $wpdb;
$page_id = YOUR_PAGE_ID; //your page id here.
$parent_page_id = $wpdb->get_var( $wpdb->prepare( 
    SELECT post_parent 
    FROM $wpdb->posts 
    WHERE ID=$page_id;
) );
$parent_page_title = get_the_title($parent_page_id);
echo $parent_page_title; //this will print parent page title.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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