php - 如何解决 PHP ACF 错误 : "Trying to access array offset on value of type bool"?

标签 php wordpress laravel roots-sage

我一直致力于开发我自己的主题,并且不得不使用我的 Laravel Sage 环境使用 ACF 制作一些自定义块。
我的目标是从转发器对象中检索文本列表。 (成功运行,但仍然显示错误)。
所以抛出该错误的代码如下:
page.blade.php:

@php
  $tv_lists = [];
  while (have_rows('tv_lists')) {
    the_row();
    $tv_lists[] = [
      'tv_list' => get_sub_field('tv_list'),
    ];
  }
@endphp

@if(get_field('tv_lists'))
          <div class="tv-lists col-12 col-md-8 col-lg-9 block-image">
            @foreach($tv_lists as $tv_list)
              @if(!empty($tv_list['tv_list']))
                <div class="tv-list quote-content">
                  <a class="tv-list-text">{{ $tv_list['tv_list'] }}</a>
                </div>
              @endif
            @endforeach
          </div>
        @endif
然后page.php中负责创建repeater块的PHP代码如下:
->addRepeater('tv_lists', [
    'conditional_logic' => [[['field' => 'links_type', 'operator' => '==', 'value' => 'list']]],
    'label' => 'TV Lists',
    'layout' => 'block',
  ])
    ->addText('tv_list', [
      'label' => 'TV List',
    ])
    ->endRepeater()
提前感谢所有花时间阅读本文的人。

最佳答案

您需要一个 if while之前的声明
所以你想做这样的事情。

@php
  $tv_lists = [];
  if (have_rows('tv_lists'){
    while (have_rows('tv_lists')) {
      the_row();
      $tv_lists[] = [
        'tv_list' => get_sub_field('tv_list'),
      ];
    }
  }
@endphp

关于php - 如何解决 PHP ACF 错误 : "Trying to access array offset on value of type bool"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63935579/

相关文章:

php - PHP 的 Elasticsearch 批量上传错误 - 已超过索引中总字段 [1000] 的限制

php - 数据表ajax根据php中的条件更改行颜色

mysql - 自使用终端安装 MySQL 以来,使用 MAMP 进行 WordPress 开发无法正常工作

php - 自定义在 Wordpress 中自动生成 Post Slug

Laravel Eloquent whereIn 按给定顺序返回

php - Laravel 什么是使用 HasFactory?

php - axios 将 array_filter 结果作为对象而不是数组接收

php - Roxy 文件人加载错误

php - 检查 php 中的日期不适用于不同月份

wordpress - 我正在使用 TCPDF 在我的 wordpress 插件中生成 pdf,但在执行时它在已发送的库 header 上有错误。