get_post_thumbnail_id

函数
get_post_thumbnail_id ( $post = null )
参数
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global `$post`.
    Required:
    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.
定义位置
相关方法
set_post_thumbnailset_post_thumbnail_sizeget_the_post_thumbnailthe_post_thumbnailget_the_post_thumbnail_url
引入
2.9.0
弃用
-

get_post_thumbnail_id: 这个函数检索给定文章的特色图片的ID。它接受一个文章ID或文章对象作为其参数,并返回特色图片的ID。

检索文章的缩略图ID。

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 );
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 18:32:58

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: