get_post_thumbnail_id

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

WordPress Version: 6.1

/**
 * Retrieves the post thumbnail ID.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 * @since 5.5.0 The return value for a non-existing post
 *              was changed to false instead of an empty string.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
 * @return int|false Post thumbnail ID (which can be 0 if the thumbnail is not set),
 *                   or false if the post does not exist.
 */
function get_post_thumbnail_id($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $thumbnail_id = (int) get_post_meta($post->ID, '_thumbnail_id', true);
    /**
     * Filters the post thumbnail ID.
     *
     * @since 5.9.0
     *
     * @param int|false        $thumbnail_id Post thumbnail ID or false if the post does not exist.
     * @param int|WP_Post|null $post         Post ID or WP_Post object. Default is global `$post`.
     */
    return (int) apply_filters('post_thumbnail_id', $thumbnail_id, $post);
}

WordPress Version: 5.9

/**
 * Retrieve post thumbnail ID.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 * @since 5.5.0 The return value for a non-existing post
 *              was changed to false instead of an empty string.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
 * @return int|false Post thumbnail ID (which can be 0 if the thumbnail is not set),
 *                   or false if the post does not exist.
 */
function get_post_thumbnail_id($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $thumbnail_id = (int) get_post_meta($post->ID, '_thumbnail_id', true);
    /**
     * Filters post thumbnail ID.
     *
     * @since 5.9.0
     *
     * @param int|false        $thumbnail_id Post thumbnail ID or false if the post does not exist.
     * @param int|WP_Post|null $post         Post ID or WP_Post object. Default is global `$post`.
     */
    return (int) apply_filters('post_thumbnail_id', $thumbnail_id, $post);
}

WordPress Version: 5.5

/**
 * Retrieve post thumbnail ID.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 * @since 5.5.0 The return value for a non-existing post
 *              was changed to false instead of an empty string.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
 * @return int|false Post thumbnail ID (which can be 0 if the thumbnail is not set),
 *                   or false if the post does not exist.
 */
function get_post_thumbnail_id($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    return (int) get_post_meta($post->ID, '_thumbnail_id', true);
}

WordPress Version: 5.4

/**
 * Retrieve post thumbnail ID.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
 * @return int|string Post thumbnail ID or empty string if the post does not exist.
 */
function get_post_thumbnail_id($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    return (int) get_post_meta($post->ID, '_thumbnail_id', true);
}

WordPress Version: 4.4

/**
 * Retrieve post thumbnail ID.
 *
 * @since 2.9.0
 * @since 4.4.0 `$post` can be a post ID or WP_Post object.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
 * @return string|int Post thumbnail ID or empty string.
 */
function get_post_thumbnail_id($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    return get_post_meta($post->ID, '_thumbnail_id', true);
}

WordPress Version: 4.3

/**
 * Retrieve Post Thumbnail ID.
 *
 * @since 2.9.0
 *
 * @param int|null $post_id Optional. Post ID.
 * @return mixed
 */
function get_post_thumbnail_id($post_id = null)
{
    $post_id = (null === $post_id) ? get_the_ID() : $post_id;
    return get_post_meta($post_id, '_thumbnail_id', true);
}

WordPress Version: 3.7

/**
 * Retrieve Post Thumbnail ID.
 *
 * @since 2.9.0
 *
 * @param int $post_id Optional. Post ID.
 * @return int
 */
function get_post_thumbnail_id($post_id = null)
{
    $post_id = (null === $post_id) ? get_the_ID() : $post_id;
    return get_post_meta($post_id, '_thumbnail_id', true);
}