WordPress: get post_parent title

Ryan picture Ryan · Mar 4, 2011 · Viewed 33.6k times · Source

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?

Answer

t31os picture t31os · Mar 5, 2011
echo get_the_title( $post->post_parent );

or

echo get_the_title( X );

Where X is any valid post/page ID.

No need to get a complete post object just for one property.