get_field()返回错误的数据
问题描述:
I am using ACF repeater fields and I am trying to write a function which counts the number of rows of the repeater. The function returns 1 even if the number of rows in a repeater are 0 or more than 0. Can someone help me to fix this ?
$rows = get_field('sub_seminars');
$row_count = count($rows);
echo count($row_count);
A var_dump
also returns int(1)
even if the number of rows in a repeater are 0 or more than 0.
我正在使用ACF转发器字段,我正在尝试编写一个计算转发器行数的函数。 即使转发器中的行数为0或大于0,该函数也会返回1. 有人帮我修复此问题吗? p>
$ rows = get_field('sub_seminars ');
$ row_count = count($ rows);
echo count($ row_count);
code> pre>
var_dump code>也返回 int(1) code>,即使转发器中的行数为0或大于0. p>
div>
答
Let's have a look at your code:
$rows = get_field('sub_seminars');
$row_count = count($rows); //returning some digit
echo count($row_count); //counting the returned digit
You are double counting the returned count and that is why it is returning 1. Try this:
$rows = get_field('sub_seminars');
$row_count = count($rows); //will return a digit
echo $row_count; //echo the count