On this page
get_post_parent( int|WP_Post|null $post = null ): WP_Post|null
Retrieves the parent post object for the given post.
Parameters
Return
WP_Post|null Parent post object, or null if there isn't one.
Source
File: wp-includes/post-template.php. View all references
function get_post_parent( $post = null ) {
$wp_post = get_post( $post );
return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null;
}
Related
Uses
| Uses | Description |
|---|---|
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| has_post_parent() wp-includes/post-template.php | Returns whether the given post has a parent post. |
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_post_parent