$post_id
和之间有什么区别get_the_ID()
?
我在上找不到任何文档$post_id
。
$post_id
和之间有什么区别get_the_ID()
?
我在上找不到任何文档$post_id
。
Answers:
get_the_ID()
返回当前帖子的ID的方式get_post
。获取帖子假定当前帖子为global
变量,$post
除非传递的参数另外指定。这意味着get_the_ID()
应该返回与中包含的相同值$post->ID
。使用get_the_ID()
可以避免直接处理全局,尽管您要间接处理它。使用get_the_ID()
通常在主题模板文件中不太容易出错。
$post_id
是一个变量名,通常用于引用帖子ID,但它并不是Core变量$post
,尽管它确实在特定上下文中定义了几次:
grep -Rn'$ post_id'* | grep全局 wp-admin / includes / class-wp-comments-list-table.php:25:全局$ post_id; wp-admin / includes / class-wp-comments-list-table.php:45:全局$ post_id,$ comment_status,$ search,$ comment_type; wp-admin / includes / class-wp-comments-list-table.php:141:全局$ post_id,$ comment_status,$ comment_type; wp-admin / includes / class-wp-comments-list-table.php:250:全局$ post_id; wp-admin / includes / ajax-actions.php:691:全局$ wp_list_table,$ post_id; wp-includes / ms-preprecated.php:115:function clear_global_post_cache($ post_id){