简体   繁体   English

ACF 中的中继器字段为空

[英]Repeater Field empty in ACF

I'm fairly new in using ACF so I used the code that was displayed in their site to display what is inside of my repeater field.我在使用 ACF 方面还很陌生,所以我使用了他们网站中显示的代码来显示我的转发器字段内的内容。

However, when I try to show the repeater's content it is empty??但是,当我尝试显示转发器的内容时​​,它是空的?? This is my code, this is still in trial mode just to see if it's working-which it isn't.这是我的代码,它仍处于试用模式,只是为了看看它是否有效 - 事实并非如此。 My repeater field already has 2 rows but it's not showing up any of those and just displays the else:我的转发器字段已经有 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;

You need to specify the page id that you have set the ACF Repeater, otherwise it will get from the current page ID需要指定你设置了ACF Repeater的page id,否则会从当前page id中获取

have_rows($field_name, $post_id); have_rows($field_name, $post_id); //syntax //语法

So, update your loop inserting the page ID you've entered the repeater data:因此,更新您的循环,插入您输入中继器数据的页面 ID:

if( have_rows('map_infogrp', 'page_id') ):

    // loop through the rows of data
        while ( have_rows('map_infogrp', 'page_id') ) : the_row();

...

If you have the fields filled in on the specific page it should be showing up.如果您在特定页面上填写了字段,它应该会显示出来。 If not, double check the field name(not label) that you used.如果没有,请仔细检查您使用的字段名称(不是标签)。 If you have more than one row make sure you're printing it out as an array too如果您有不止一行,请确保您也将其作为数组打印出来

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

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