繁体   English   中英

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的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();

...

如果您在特定页面上填写了字段,它应该会显示出来。 如果没有,请仔细检查您使用的字段名称(不是标签)。 如果您有不止一行,请确保您也将其作为数组打印出来

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM