Here’s a simple function to determine if a post, page, or custom post has children in WordPress. It works by getting the children of the current post and returning a count. It will return 0 (false) if there are no children and some positive integer (true) if there are children.
function has_children() {
global $post;
return count( get_posts( array('post_parent' => $post->ID, 'post_type' => $post->post_type) ) );
}
Use it in your page or post templates:
if ( has_children() ) {
// do something if this item has children
}