Skip to content

Instantly share code, notes, and snippets.

@morgyface
Created September 14, 2018 11:10
Show Gist options
  • Select an option

  • Save morgyface/bac286aa7a3926c90a47b005d93f5bc8 to your computer and use it in GitHub Desktop.

Select an option

Save morgyface/bac286aa7a3926c90a47b005d93f5bc8 to your computer and use it in GitHub Desktop.
WordPress | Checks to see if a post is a child, that is; does the post have a parent?
<?php
// Check if post has any parents
function is_child($post_id) {
$post = get_post($post_id);
$parent = $post->post_parent;
if( $parent != 0 ) {
return true;
} else {
return false;
}
}
?>
<?php
// Example
if( is_child( $post_id ) ) {
echo 'I have a parent I am a child';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment