首页 > 解决方案 > 使用带有特定 postID 的 get_field 返回空

问题描述

我试图在循环中使用 get_field 来检索一些自定义字段值,但是在使用 get_field('container', post_id) 时,该值始终为空。

我什至尝试在块文件中使用它,同样的情况发生了。

  $container = get_field('container'); // this works
  $test_container = get_field('container', 144); //this returns empty,  post id === 144 

标签: phpwordpressadvanced-custom-fields

解决方案


Did you try the_field() function.

In ACF the_field() function is used to display the value of a specific field. it is same as get_field(). https://www.advancedcustomfields.com/resources/the_field/

<?php if( get_field('container') ): ?>
   <p><?php the_field('container', 144); ?> </p>
<?php endif; ?>

推荐阅读