Erasersharp
Erasersharp

Reputation: 368

Get the parent page title name from a specific page ID number

I have a page ID number stored in a variable. However I'm trying to access that specific page ID numbers parent page title.

Could someone lead me in the right direction.

Upvotes: 1

Views: 1264

Answers (2)

Tomasz Dziuda
Tomasz Dziuda

Reputation: 346

Please try to use the following code:

get_the_title(wp_get_post_parent_id($your_post_ID));

Upvotes: 4

sietse85
sietse85

Reputation: 1506

For the current page:

<?php
echo empty( $post->post_parent ) ? get_the_title( $post->ID ) : get_the_title( $post->post_parent );
?>

If that ID is some others page ID i would say run a query on the DB itself to get that title.

Upvotes: 0

Related Questions