Created
February 11, 2012 16:31
-
-
Save vc27/1801834 to your computer and use it in GitHub Desktop.
Will check if given post_id has children in given post_type
This file contains 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
/** | |
* Has Children | |
**/ | |
function has_children( $post_id, $post_type ) { | |
global $wpdb; | |
$querystr = "SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_type = '$post_type' AND $wpdb->posts.post_parent = '$post_id' LIMIT 1"; | |
$results = $wpdb->get_results( $querystr, ARRAY_N ); | |
if ( is_numeric( $results[0][0] ) AND $results[0][0] > 0 ) | |
return true; | |
else | |
return false; | |
} // end function has_children |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment