[英]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.