Last active
October 6, 2015 02:38
-
-
Save hissy/2921668 to your computer and use it in GitHub Desktop.
check the post has children #WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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