wp_get_post_parent_id() WordPress Function

The wp_get_post_parent_id() function is used to get the post parent id of the current post.

wp_get_post_parent_id( int|WP_Post|null $post = null ) #

Returns the ID of the post’s parent.


Parameters

$post

(int|WP_Post|null)(Optional) Post ID or post object. Defaults to global $post.

Default value: null


Top ↑

Return

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


Top ↑

Source

File: wp-includes/post.php

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


Top ↑

Changelog

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

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More