Search code examples
wordpressparenttitle

WordPress: get post_parent title


I've created a custom sidebar that grabs the post parent's pages:

query_posts("post_type=page&post_parent=6"); 

I'd like to grab the title of the post_parent (i.e. "About"). the_title won't work because it's the title of the child pages.

How can I output the post_parent title?


Solution

  • It looks like you've already got the ID of the parent post, so you can just use this:

    <?php
        $parent_post_id = 6;
        $parent_post = get_post($parent_post_id);
        $parent_post_title = $parent_post->post_title;
        echo $parent_post_title;
    ?>
    

    (Insert your parent post id at $parent_post_id)

    Ref: http://codex.wordpress.org/Function_Reference/get_post