get_post_type

The timeline below displays how wordpress function get_post_type has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.3

/**
 * Retrieves the post type of the current post or of a given post.
 *
 * @since 2.1.0
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post.
 * @return string|false          Post type on success, false on failure.
 */
function get_post_type($post = null)
{
    $post = get_post($post);
    if ($post) {
        return $post->post_type;
    }
    return false;
}

WordPress Version: 4.6

/**
 * Retrieves the post type of the current post or of a given post.
 *
 * @since 2.1.0
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post.
 * @return string|false          Post type on success, false on failure.
 */
function get_post_type($post = null)
{
    if ($post = get_post($post)) {
        return $post->post_type;
    }
    return false;
}

WordPress Version: 4.3

/**
 * Retrieve the post type of the current post or of a given post.
 *
 * @since 2.1.0
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post.
 * @return string|false          Post type on success, false on failure.
 */
function get_post_type($post = null)
{
    if ($post = get_post($post)) {
        return $post->post_type;
    }
    return false;
}

WordPress Version: 4.1

/**
 * Retrieve the post type of the current post or of a given post.
 *
 * @since 2.1.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
 * @return string|false Post type on success, false on failure.
 */
function get_post_type($post = null)
{
    if ($post = get_post($post)) {
        return $post->post_type;
    }
    return false;
}

WordPress Version: 4.0

/**
 * Retrieve the post type of the current post or of a given post.
 *
 * @since 2.1.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
 * @return string|bool Post type on success, false on failure.
 */
function get_post_type($post = null)
{
    if ($post = get_post($post)) {
        return $post->post_type;
    }
    return false;
}

WordPress Version: 3.9

/**
 * Retrieve the post type of the current post or of a given post.
 *
 * @since 2.1.0
 *
 * @param int|WP_Post $post Optional. Post ID or post object.
 * @return string|bool Post type on success, false on failure.
 */
function get_post_type($post = null)
{
    if ($post = get_post($post)) {
        return $post->post_type;
    }
    return false;
}

WordPress Version: 3.7

/**
 * Retrieve the post type of the current post or of a given post.
 *
 * @since 2.1.0
 *
 * @param int|object $post Optional. Post ID or post object. Default is the current post from the loop.
 * @return string|bool Post type on success, false on failure.
 */
function get_post_type($post = null)
{
    if ($post = get_post($post)) {
        return $post->post_type;
    }
    return false;
}