WordPress at a glance

get_post_thumbnail_id() WP 1.0

Retrieve post thumbnail ID.

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.

Return

String/Int. Post thumbnail ID or empty string.

Usage

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

Changelog

Since 2.9.0 Introduced.
Since 4.4.0 $post can be a post ID or WP_Post object.

Code of get post thumbnail id: wp-includes/post-thumbnail-template.php WP 5.2.3

<?php
function get_post_thumbnail_id( $post = null ) {
	$post = get_post( $post );
	if ( ! $post ) {
		return '';
	}
	return 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
    Hello, !     Log In . Register