WordPress at a glance

get_post_thumbnail_id() WP 1.0

Retrieve post thumbnail ID.


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

Works based on: get_post_meta()
1 time = 0.00126s = very slow | 50000 times = 0.28s = very fast | PHP 7.1.5, WP 4.8.1

No Hooks.


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

Список изменений

С версии 2.9.0 Введена.
С версии 4.4.0 $post can be a post ID or WP_Post object.
С версии 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.5.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 );

Related Functions

From tag: Thumbnail (images)

More from category: Thumbnails

More from Template Tags: Post Thumbnails

No comments
    Log In . Register