From 4d5709b11d7d0a76148a3fbdd2dbcebeb3c9bc9b Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 10 Apr 2010 11:42:45 +0000 Subject: [PATCH] Introduce is_post_type_hierarchical(). Props ptahdunbar. See #12950 git-svn-id: https://develop.svn.wordpress.org/trunk@14053 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/post.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wp-includes/post.php b/wp-includes/post.php index 3fd27d6823..b26d038186 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -660,6 +660,28 @@ function get_post_stati( $args = array(), $output = 'names', $operator = 'or' ) return $post_statuses; } +/** + * Whether the post type is hierarchical. + * + * A false return value might also mean that the post type does not exist. + * + * @since 3.0.0 + * @see get_post_type_object + * + * @param string|int|object $post Post type name, post id, or a post object. + * @return bool true if post type is hierarchical, else false. + */ +function is_post_type_hierarchical( $post = false ) { + if ( is_string($post) && $is_post_type = get_post_type_object($post) ) + return $is_post_type->hierarchical; + + $ptype = get_post( $post ); + if ( $ptype && $is_post_type = get_post_type_object($ptype->post_type) ) + return $is_post_type->hierarchical; + + return false; +} + /** * Retrieve the post type of the current post or of a given post. *