wp_get_post_parent_id()
Returns the ID of the post's parent.
No Hooks.
Returns
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() wp get post parent id code WP 7.0
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;
}