get_post_thumbnail_id

Retrieve post thumbnail ID.

Description

(string|int) get_post_thumbnail_id( (null) $post = null ); 

Returns (string|int)

Post thumbnail ID or empty string.

Parameters (1)

0. $post — Optional. (null) => null
Post ID or WP_Post object. Default is global $post..

Usage

  1. if ( !function_exists( 'get_post_thumbnail_id' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-thumbnail-template.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global `$post`. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_post_thumbnail_id($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post-thumbnail-template.php  
  1. function get_post_thumbnail_id( $post = null ) { 
  2. $post = get_post( $post ); 
  3. if ( ! $post ) { 
  4. return ''; 
  5. return get_post_meta( $post->ID, '_thumbnail_id', true );