1. 首页
  2. WordPress 函数手册

get_the_ID()

get_the_ID()

检索WordPress循环中当前项的ID。
Retrieve the ID of the current item in the WordPress Loop.

目录锚点:#返回#源码#笔记


返回(Return)

(int|false)WordPress循环中当前项的ID。如果未设置$post,则为False。


源码(Source)

/**
 * Retrieve the ID of the current item in the WordPress Loop.
 *
 * @since 2.1.0
 *
 * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
 */
function get_the_ID() {
	$post = get_post();
	return ! empty( $post ) ? $post->ID : false;
}
更新版本 源码位置 使用 被使用
2.1.0 wp-includes/post-template.php:27 14 1 function

笔记(Notes)

需要注意的是,如果这是在博客主页上运行的,它将返回列出的第一个帖子ID,而不是博客主页ID。
后定位标识符
存储ID

get_the_ID() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_the_id/