On this page
get_the_ID(): int|false
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.
Source
File: wp-includes/post-template.php. View all references
function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
$post = get_post();
return ! empty( $post ) ? $post->ID : false;
}
Related
Uses
| Uses | Description |
|---|---|
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| print_embed_sharing_dialog() wp-includes/embed.php | Prints the necessary markup for the embed sharing dialog. |
| wp_dashboard_recent_posts() wp-admin/includes/dashboard.php | Generates Publishing Soon and Recently Published sections. |
| wp_get_archives() wp-includes/general-template.php | Displays archive links based on type and format. |
| get_post_comments_feed_link() wp-includes/link-template.php | Retrieves the permalink for the post comments feed. |
| prepend_attachment() wp-includes/post-template.php | Wraps attachment in paragraph tag before content. |
| the_ID() wp-includes/post-template.php | Displays the ID of the current item in the WordPress Loop. |
| wp_video_shortcode() wp-includes/media.php | Builds the Video shortcode output. |
| wp_audio_shortcode() wp-includes/media.php | Builds the Audio shortcode output. |
| is_sticky() wp-includes/post.php | Determines whether a post is sticky. |
| get_post_custom() wp-includes/post.php | Retrieves post meta fields, based on post ID. |
| get_comment_id_fields() wp-includes/comment-template.php | Retrieves hidden input HTML for replying to comments. |
| wp_list_comments() wp-includes/comment-template.php | Displays a list of comments. |
| get_trackback_url() wp-includes/comment-template.php | Retrieves the current post’s trackback URL. |
| comments_popup_link() wp-includes/comment-template.php | Displays the link to the comments for the current post ID. |
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_the_id