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
This commit is contained in:
parent
c3ec0a0c9c
commit
d7a1de87f0
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue