Make WordPress Core

Changeset 14158


Ignore:
Timestamp:
04/18/2010 05:40:50 PM (15 years ago)
Author:
nacin
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r14155 r14158  
    667667
    668668    return false;
     669}
     670
     671/**
     672 * Checks if a post type is registered, can also check if the current or specified post is of a post type.
     673 *
     674 * @since 3.0.0
     675 * @uses get_post_type()
     676 *
     677 * @param string|array $types Type or types to check. Defaults to all post types.
     678 * @param int $id Post ID. Defaults to current ID.
     679 * @return bool
     680 */
     681function is_post_type( $types = false, $id = false ) {
     682    $types = ( $types === false ) ? get_post_types() : (array) $types;
     683    return in_array( get_post_type( $id ), $types );
    669684}
    670685
Note: See TracChangeset for help on using the changeset viewer.