get_the_ID() WordPress Function

The get_the_ID() function is used to retrieve the post ID of the current post. This function can be used within the loop to return the post ID of the post being processed.

get_the_ID() #

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


Return

(int|false) The ID of the current item in the WordPress Loop. False if $post is not set.


Top ↑

Source

File: wp-includes/post-template.php

function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
	$post = get_post();
	return ! empty( $post ) ? $post->ID : false;
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.