wp_get_post_parent_id()WP 3.1.0

Returns the ID of the post's parent.

No Hooks.

Return

Int|false. Post parent ID (which can be 0 if there is no parent), or false if the post does not exist.

Usage

wp_get_post_parent_id( $post );
$post(int|WP_Post|null)
Post ID or post object.
Default: global $post

Changelog

Since 3.1.0 Introduced.
Since 5.9.0 The $post parameter was made optional.

wp_get_post_parent_id() code WP 6.5.2

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;
}