WordPress:无法读取属于字段组的自定义字段

WordPress: Unable to read custom field that is part of a fields group

我向字段组添加了一个新的自定义字段,仅用于呈现主页。当尝试使用下面的代码读取和显示该字段的内容时,没有任何反应。我确信读取自定义字段的方式应该是这样的。我没有收到任何错误消息。你能帮忙解决这个问题吗?这是在 WordPress 网站上完成的。

<div class="bg-white-base relative pt-row pb-row pl pr">
  <div class="wrap-x">
    <div class="inside mini">
      
      <?php if ( $headline = get_sub_field( 'slider_-_h1' ) ) : ?>
      <h2 class="mb color-purple-base">
        <?php echo $headline; ?>
      </h2>
      <?php endif; ?>

      <?php if ( $subheadline = get_sub_field( 'slider_-_h2' ) ) : ?>
      <h3 class="mb alt-heading h5">
        <?php echo $subheadline; ?>
      </h3>
      <?php endif; ?>

      <?php if ( $text_area = get_sub_field( 'slider-_shortcode' ) ) : ?>
      <article class="body-area mt2x">
        <?php echo $text_area; ?>
      </article>
      <?php endif; ?>

    </div>
  </div>
</div>

get_sub_field() 应该在循环中使用。当你使用一个组时,你可以使用像这样的循环:

while( have_rows('hero') ): the_row();
........
endwhile;

一切都在这里解释:https://www.advancedcustomfields.com/resources/group/