Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active October 6, 2015 02:38
Show Gist options
  • Save hissy/2921668 to your computer and use it in GitHub Desktop.
Save hissy/2921668 to your computer and use it in GitHub Desktop.
check the post has children #WordPress
<?php
/**
* Usage
* if ( has_children( get_the_ID() ) ) :
* // this post has children
* else:
* // this post has no children
* endif;
*/
function has_children( $post ) {
$post = get_post( $post );
if ( !$post || is_wp_error( $post ) )
return false;
$children = get_pages("child_of=".$post->ID);
if ( count( $children ) != 0 ) { return true; } // Has Children
else { return false; } // No children
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment