【问题标题】:How to get the data from Advanced Custom Fields with sub group如何从具有子组的高级自定义字段中获取数据
【发布时间】:2021-12-26 07:45:37
【问题描述】:

我无法使用 ACF 将数据导入首页(front-page.php)。我试着写这样的代码。但我做不到。请告诉我如何使用 ACF 获取数据。

字段名:left-result 卷曲类型:组 子字段:左标题

   <?php if (have_rows('left-result')) : ?>
        <li>
            <?php while (have_rows('left-result')) : the_row(); 
              $t_ttl = get_sub_field('left-title');
            ?>
            <h1><?php echo $t_ttl; ?></h1>
          <?php endwhile; ?>
        </li>
        <?php endif; ?>

【问题讨论】:

  • 你得到&lt;li&gt;元素了吗?因为如果没有,你就没有打到你的 acf 组。如果您不在循环内,则需要将 ID 指定给 ACF。 have_rows('left-result', get_the_ID())
  • 您可以通过自定义字段 > 工具 > 导出文件分享您的 ACF 代码吗?
  • 我拿到了我的文件,但是如何分享给你呢?

标签: wordpress grouping advanced-custom-fields


【解决方案1】:

尝试使用唯一键而不是field_name

if( have_rows('parent_field') ):
        while ( have_rows('parent_field') ) : the_row();
            $sub_value = get_sub_field('sub_field');
            // Do something...
        endwhile;
    else :
        // no rows found
    endif;

【讨论】:

  • 它没有钥匙。它有名称和类型。
  • 在您的仪表板中转到自定义字段 > 自定义字段,然后选择您的字段组。单击浏览器窗口右上角的“屏幕选项”。将“显示字段键”设置为“是”查看组列表中字段编号旁边的字段键。
  • 我无法导入这封信,但它有空的 h1 标签
猜你喜欢
  • 2014-02-06
  • 2016-05-31
  • 2015-07-07
  • 2016-03-24
  • 1970-01-01
  • 2019-06-17
  • 1970-01-01
  • 2016-06-13
  • 1970-01-01
相关资源
最近更新 更多