has_post_parent()
Returns whether the given post has a parent post.
Uses: get_post_parent()
No Hooks.
Return
true|false
. Whether the post has a parent post.
Usage
has_post_parent( $post );
- $post(int|WP_Post|null)
- Post ID or WP_Post object.
Default: global $post
Examples
#1 Check the availability of the parent post
$post_id = 5; if ( has_post_parent( $post_id ) ) { echo 'The specified post has a parent post'; } else { echo 'The specified post does not have a parent post'; }
Changelog
Since 5.7.0 | Introduced. |
has_post_parent() has post parent code WP 6.7.1
function has_post_parent( $post = null ) { return (bool) get_post_parent( $post ); }