函数原型
get_post_thumbnail_id( int|WP_Post $post = null ): int|false
函数描述
Retrieves the post thumbnail ID.
是否弃用
未弃用
函数参数
-
$post
int|WP_Post
Optional - Post ID or WP_Post object. Default is global
$post.Default:
null
函数返回值
int|false Post thumbnail ID (which can be 0 if the thumbnail is not set), or false if the post does not exist.
函数位置
File: wp-includes/post-thumbnail-template.php.
函数源码
function get_post_thumbnail_id( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$thumbnail_id = (int) get_post_meta( $post->ID, '_thumbnail_id', true );
/**
* Filters the post thumbnail ID.
*
* @since 5.9.0
*
* @param int|false $thumbnail_id Post thumbnail ID or false if the post does not exist.
* @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`.
*/
return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id, $post );
}
源码链接
变更日志
| 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. |

