wp_get_post_parent_id( int|WP_Post|null $post = null ): int|false

Returns the ID of the post’s parent.

Parameters

$postint|WP_Post|nulloptional
Post ID or post object. Defaults to global $post.

Default:null

Return

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

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

Changelog

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

User Contributed Notes

You must log in before being able to contribute a note or feedback.