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
檢視更多 >