get_the_ID()
退货the ID of the current post 通过以下方式get_post
. 获取帖子assumes the current post to be the global
variable $post
除非传递的参数另有规定。这意味着get_the_ID()
应返回与中包含的值相同的值$post->ID
. 使用get_the_ID()
让您避免直接与全局打交道,尽管您是间接地与全局打交道。使用get_the_ID()
在主题模板文件中不太容易出错。
$post_id
是一个通常用于引用post ID的变量名,但它不是一个核心变量$post
虽然它在特定的上下文中被定义过几次:
grep -Rn \'$post_id\' * |grep global
wp-admin/includes/class-wp-comments-list-table.php:25: global $post_id;
wp-admin/includes/class-wp-comments-list-table.php:45: global $post_id, $comment_status, $search, $comment_type;
wp-admin/includes/class-wp-comments-list-table.php:141: global $post_id, $comment_status, $comment_type;
wp-admin/includes/class-wp-comments-list-table.php:250: global $post_id;
wp-admin/includes/ajax-actions.php:691: global $wp_list_table, $post_id;
wp-includes/ms-deprecated.php:115:function clear_global_post_cache( $post_id ) {