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
Int/false. Post thumbnail ID (which can be 0 if the thumbnail is not set), or false if the post does not exist.
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. |
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() get post thumbnail id WP 5.6
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)
- add_image_size()
- delete_post_thumbnail()
- get_intermediate_image_sizes()
- get_the_post_thumbnail()
- get_the_post_thumbnail_caption()
- get_the_post_thumbnail_url()
- has_image_size()