Skip to content

Instantly share code, notes, and snippets.

@vc27
Created February 11, 2012 16:31
Show Gist options
  • Save vc27/1801834 to your computer and use it in GitHub Desktop.
Save vc27/1801834 to your computer and use it in GitHub Desktop.
Will check if given post_id has children in given post_type
/**
* 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