ACF 中的转发器字段为空
Repeater Field empty in ACF
我在使用 ACF 方面相当陌生,所以我使用了他们网站上显示的代码来显示我的转发器字段中的内容。
但是,当我尝试显示转发器的内容时,它是空的??
这是我的代码,它仍处于试用模式,只是为了看看它是否能正常工作——但事实并非如此。我的转发器字段已经有 2 行,但它没有显示其中任何一行,只显示其他内容:
// check if the repeater field has rows of data
if( have_rows('map_infogrp') ):
// loop through the rows of data
while ( have_rows('map_infogrp') ) : the_row();
// display a sub field value
the_sub_field('google_map');
the_sub_field('branch_name');
//$street = get_sub_field('street');
//$district = get_sub_field('district');
//$phonenum = get_sub_field('phone_number');
//$email = get_sub_field('email');
endwhile;
else:
echo 'why is this empty???';
endif;
如果您在特定页面上填写了字段,它应该会显示出来。如果不是,请仔细检查您使用的字段名称(不是标签)。如果你有不止一行,确保你也将它作为一个数组打印出来
您需要指定您设置ACF Repeater的页面id,否则将从当前页面ID获取
have_rows($field_name, $post_id); //syntax
因此,更新您的循环,插入您输入转发器数据的页面 ID:
if( have_rows('map_infogrp', 'page_id') ):
// loop through the rows of data
while ( have_rows('map_infogrp', 'page_id') ) : the_row();
...
我在使用 ACF 方面相当陌生,所以我使用了他们网站上显示的代码来显示我的转发器字段中的内容。
但是,当我尝试显示转发器的内容时,它是空的?? 这是我的代码,它仍处于试用模式,只是为了看看它是否能正常工作——但事实并非如此。我的转发器字段已经有 2 行,但它没有显示其中任何一行,只显示其他内容:
// check if the repeater field has rows of data
if( have_rows('map_infogrp') ):
// loop through the rows of data
while ( have_rows('map_infogrp') ) : the_row();
// display a sub field value
the_sub_field('google_map');
the_sub_field('branch_name');
//$street = get_sub_field('street');
//$district = get_sub_field('district');
//$phonenum = get_sub_field('phone_number');
//$email = get_sub_field('email');
endwhile;
else:
echo 'why is this empty???';
endif;
如果您在特定页面上填写了字段,它应该会显示出来。如果不是,请仔细检查您使用的字段名称(不是标签)。如果你有不止一行,确保你也将它作为一个数组打印出来
您需要指定您设置ACF Repeater的页面id,否则将从当前页面ID获取
have_rows($field_name, $post_id); //syntax
因此,更新您的循环,插入您输入转发器数据的页面 ID:
if( have_rows('map_infogrp', 'page_id') ):
// loop through the rows of data
while ( have_rows('map_infogrp', 'page_id') ) : the_row();
...