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

前端 未结 1 1082
陌清茗
陌清茗 2021-02-15 00:54

I think it must be pretty basic question but I am only starting. Can someone have a look at the 3 versions of the same (?) code below and say what the difference is? All of them

相关标签:
1条回答
  • 2021-02-15 01:24

    If you're inside a WordPress loop, then $post->ID it's the same as using get_the_ID()

    You shouldn't need to globalize $post since it's already in the scope of a WordPress loop.

    I've never seen code using $the_ID, so I would avoid using that.

    The safest choice would be to use get_the_ID()

    0 讨论(0)
提交回复
热议问题