Returns the ID of the post’s parent.
Parameters
$post
int|WP_Post|nulloptional- Post ID or post object. Defaults to global $post.
Default:
null
Source
function wp_get_post_parent_id( $post = null ) {
$post = get_post( $post );
if ( ! $post || is_wp_error( $post ) ) {
return false;
}
return (int) $post->post_parent;
}
This only obtains the parent immediately of the post.
If you need the parent of a parent page, use
get_post_ancestors