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。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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
查看更多 >