Uses
Uses | Description |
---|---|
wp-includes/post.php: get_post_meta() | Retrieves a post meta field for the given post ID. |
wp-includes/post.php: get_post() | Retrieves post data given a post ID or post object. |
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.
add_theme_support( 'post-thumbnails' );
in its functions.php file. See also Post Thumbnails.File: wp-includes/post-thumbnail-template.php
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 ); }
Version | Description |
---|---|
5.5.0 | The return value for a non-existing post was changed to false instead of an empty string. |
4.4.0 | $post can be a post ID or WP_Post object. |
2.9.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_post_thumbnail_id