【问题标题】:get_field() returns wrong dataget_field() 返回错误数据
【发布时间】:2017-08-22 09:43:46
【问题描述】:

我正在使用 ACF 转发器字段,并且我正在尝试编写一个函数来计算转发器的行数。即使转发器中的行数为 0 或大于 0,该函数也会返回 1。 有人可以帮我解决这个问题吗?

$rows = get_field('sub_seminars');
$row_count = count($rows);
echo count($row_count);

即使转发器中的行数为 0 或大于 0,var_dump 也会返回 int(1)

【问题讨论】:

  • 检查这个 echo $row_count;
  • 还是没有运气@anju

标签: php wordpress advanced-custom-fields


【解决方案1】:

让我们看看你的代码:

$rows = get_field('sub_seminars');
$row_count = count($rows);  //returning some digit
echo count($row_count);  //counting the returned digit

您正在重复计算返回的计数,这就是它返回 1 的原因。试试这个:

$rows = get_field('sub_seminars');
$row_count = count($rows);     //will return a digit
echo $row_count;  //echo the count

【讨论】:

  • 谢谢@roundAbout
  • 乐于帮助@Damon
猜你喜欢
  • 2017-05-28
  • 2019-11-03
  • 2014-09-13
  • 2021-02-24
  • 2019-11-16
  • 2020-03-04
  • 1970-01-01
  • 2020-08-04
  • 2017-05-23
相关资源
最近更新 更多