get_post_parent() – Retrieves the parent post object for the given post.

You appear to be a bot. Output may be restricted

Description

Retrieves the parent post object for the given post.

Usage

$WP_Post|null = get_post_parent( $post );

Parameters

$post
( int|WP_Post|null ) optional – Optional. Post ID or WP_Post object. Default is global $post.

Returns

WP_Post|null Parent post object, or null if there isn't one.

Source

File name: wordpress/wp-includes/post-template.php
Lines:

1 to 4 of 4
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 on GitHub View on Trac