On this page
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|null Optional-
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
File: wp-includes/post.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_get_post_parent_id