wpseek.com
A WordPress-centric search engine for devs and theme authors



get_post_thumbnail_id › WordPress Function

Since2.9.0
Deprecatedn/a
get_post_thumbnail_id ( $post = null )
Parameters:
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global `$post`.
    Required: No
    Default: null
Returns:
  • (int|false) Post thumbnail ID (which can be 0 if the thumbnail is not set), or false if the post does not exist.
Defined at:
Codex:
Change Log:
  • 4.4.0
  • 5.5.0

Retrieves the post thumbnail ID.



Source

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 );
}