From d7a1de87f0d452a7fca259542f357a577c6e7df3 Mon Sep 17 00:00:00 2001 From: Andrew 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: https://develop.svn.wordpress.org/trunk@14158 602fd350-edb4-49c9-b593-d223f7449a82 --- 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. *