From e47e3cc31c933ca0808884b24eb8c07fdfd1e058 Mon Sep 17 00:00:00 2001 From: nacin Date: Sun, 18 Apr 2010 17:40:50 +0000 Subject: [PATCH] Introduce is_post_type(). Can check if a post type is registered, or also if a post (current or specified) is of a certain post type. fixes #12588, props sirzooro, blepoxp, rmccue git-svn-id: http://svn.automattic.com/wordpress/trunk@14158 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wp-includes/post.php b/wp-includes/post.php index e70bd43392..93ae587e07 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -668,6 +668,21 @@ function is_post_type_hierarchical( $post = false ) { return false; } +/** + * Checks if a post type is registered, can also check if the current or specified post is of a post type. + * + * @since 3.0.0 + * @uses get_post_type() + * + * @param string|array $types Type or types to check. Defaults to all post types. + * @param int $id Post ID. Defaults to current ID. + * @return bool + */ +function is_post_type( $types = false, $id = false ) { + $types = ( $types === false ) ? get_post_types() : (array) $types; + return in_array( get_post_type( $id ), $types ); +} + /** * Retrieve the post type of the current post or of a given post. *