has_post_parent() WordPress Function

The has_post_parent() function in WordPress allows you to check if a post has a parent post. This is useful for checking if a post is a child post or not.

has_post_parent( int|WP_Post|null $post = null ) #

Returns whether the given post has a parent post.


Parameters

$post

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

Default value: null


Top ↑

Return

(bool) Whether the post has a parent post.


Top ↑

Source

File: wp-includes/post-template.php

function has_post_parent( $post = null ) {
	return (bool) get_post_parent( $post );
}


Top ↑

Changelog

Changelog
VersionDescription
5.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.