Title: get_post_parent
Published: March 9, 2021
Last modified: August 20, 2026

---

# get_post_parent( int|WP_Post|null $post = null ): 󠀁[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)󠁿|null

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#changelog)

Retrieves the parent post object for the given post.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
|nulloptional

Post ID or [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
object. Default is global $post.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#return)󠁿

 [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)|null Parent
post object, or null if there isn’t one.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#source)󠁿

    ```php
    function get_post_parent( $post = null ) {
    	$wp_post = get_post( $post );
    	return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/post-template.php#L2086)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/post-template.php#L2086-L2089)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#related)󠁿

| Uses | Description | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

| Used by | Description | 
| [has_post_parent()](https://developer.wordpress.org/reference/functions/has_post_parent/)`wp-includes/post-template.php` |

Returns whether the given post has a parent post.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_parent/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_parent%2F)
before being able to contribute a note or feedback.