我在使用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;
答案 0 :(得分:2)
您需要指定已设置ACF中继器的页面ID,否则它将从当前页面ID中获取
have_rows($ field_name,$ post_id); //语法
因此,更新您的循环,插入您已输入转发器数据的页面ID:
if( have_rows('map_infogrp', 'page_id') ):
// loop through the rows of data
while ( have_rows('map_infogrp', 'page_id) ) : the_row();
...
答案 1 :(得分:0)
如果您在特定页面上填写了字段,则应显示该字段。如果没有,请仔细检查您使用的字段名称(不是标签)。如果您有多行,请确保将其作为数组打印出来