There are many way to do that and WordPress has some default functions to get that parent page. In fact there is a thing called post_parent
in post
object. However, you can use the below techniques I think-
-
get_post_ancestors( $post )
function. Here$post
is ID or object. Here you’ll find the documentation. -
You can also use
wp_get_post_parent_id( $post_ID )
. Here you’ll find the documentation. -
You can also do that by getting the
post_parent
like
$post->post_parent
. Then useget_post()
or any other function to get that page variable name.
Hope that thing helps.