WordPress at Your Fingertips

get_post_thumbnail_id() WP 1.0

Retrieve post thumbnail ID.

1 time — 0.00126 sec (very slow) | 50000 times — 0.28 sec (very fast) | PHP 7.1.5, WP 4.8.1

No Hooks.


Int|false. Post thumbnail ID (which can be 0 if the thumbnail is not set), or false if the post does not exist.


get_post_thumbnail_id( $post );
Post ID or WP_Post object.
Default: global $post


Since 2.9.0 Introduced.
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.

Code of get_post_thumbnail_id() WP 5.8.1

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

Thumbnail (images)


Post Thumbnails

No comments
    Log In