ACF 中的中继器字段为空

Ami*_*l M 3 php wordpress advanced-custom-fields

我在使用 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;
Run Code Online (Sandbox Code Playgroud)

cai*_*isk 5

需要指定你设置了ACF Repeater的page id,否则会从当前page 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();

...
Run Code Online (Sandbox Code Playgroud)