脚本宝典收集整理的这篇文章主要介绍了php – get_the_id vs. post-> ID vs. the_id / get_post_meta,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
应该使用哪个:$post-> ID,$the_ID或get_the_id()?
是否有必要拥有全球$post;?
global $post; $content = get_post_meta( $post->ID,‘my_custom_field',true ); echo $content;
要么
$content = get_post_meta( $the_ID,true ); echo $content;
要么
$content = get_post_meta( get_the_id(),‘my_custom_field’,true ); echo $content;
非常感谢您的帮助
您不应该全局化$post,因为它已经在wordpress循环的范围内.
我从未见过使用$the_ID的代码,所以我会避免使用它.
最安全的选择是使用get_the_ID()
以上是脚本宝典为你收集整理的php – get_the_id vs. post-> ID vs. the_id / get_post_meta全部内容,希望文章能够帮你解决php – get_the_id vs. post-> ID vs. the_id / get_post_meta所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。