WordPress at Your Fingertips

get_post_parent() WP 1.0

Retrieves the parent post object for the given post.

Uses: get_post()

No Hooks.

Return

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

Usage

get_post_parent( $post );
$post(int|WP_Post|null)
Post ID or WP_Post object.
Default: global $post

Changelog

Since 5.7.0 Introduced.

Code of get_post_parent() WP 5.8

<?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;
}

From category: Other

No comments
    Log In