get_the_ID

Retrieve the ID of the current item in the WordPress Loop.

Description

(int|false) get_the_ID(); 

Returns (int|false)

The ID of the current item in the WordPress Loop. False if $post is not set.


Usage

  1. if ( !function_exists( 'get_the_ID' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = get_the_ID(); 
  7.  

Defined (1)

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

/wp-includes/post-template.php  
  1. function get_the_ID() { 
  2. $post = get_post(); 
  3. return ! empty( $post ) ? $post->ID : false;