get_field() returns 数据错误
get_field() returns wrong data
我正在使用 ACF 转发器字段,我正在尝试编写一个函数来计算转发器的行数。即使转发器中的行数为 0 或多于 0,函数 returns 1。
有人可以帮我解决这个问题吗?
$rows = get_field('sub_seminars');
$row_count = count($rows);
echo count($row_count);
A var_dump
也 returns int(1)
即使转发器中的行数为 0 或多于 0。
让我们看看您的代码:
$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
我正在使用 ACF 转发器字段,我正在尝试编写一个函数来计算转发器的行数。即使转发器中的行数为 0 或多于 0,函数 returns 1。 有人可以帮我解决这个问题吗?
$rows = get_field('sub_seminars');
$row_count = count($rows);
echo count($row_count);
A var_dump
也 returns int(1)
即使转发器中的行数为 0 或多于 0。
让我们看看您的代码:
$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