WordPress at a glance

get_post_thumbnail_id() WP 1.0

Retrieve post thumbnail ID.

  • Since 4.4.0 $post can be a post ID or WP_Post object.
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

Code of get_post_thumbnail_id: wp-includes/post-thumbnail-template.php VER 4.9.8

<?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

No comments
    Hello, !     Log In . Register