小编The*_*ear的帖子

get_the_id vs. post-> ID vs. the_id/get_post_meta

我认为这一定是非常基本的问题,但我只是开始.有人可以查看下面相同(?)代码的3个版本,并说明有什么区别?所有这些似乎都在我正在研究的循环中正常工作.

哪个应该使用:$post->ID,$the_IDget_the_id()?有必要global $post;吗?

global $post;
$content = get_post_meta( $post->ID, ‘my_custom_field', true );
echo  $content;
Run Code Online (Sandbox Code Playgroud)

要么

$content = get_post_meta( $the_ID, ‘my_custom_field', true );
echo  $content;
Run Code Online (Sandbox Code Playgroud)

要么

$content = get_post_meta( get_the_id(), ‘my_custom_field’, true );
echo  $content;
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助

php variables wordpress global

9
推荐指数
1
解决办法
5313
查看次数

标签 统计

global ×1

php ×1

variables ×1

wordpress ×1