[英]Wordpress ACF Repeater sub fields
我在 Wordpress 中遇到了 ACF 中继器子字段链接对象未在前端返回 href 的问题。 基本上前端中的链接不会输出任何在WP admin中设置的链接。 文本输出正在工作。
中继器字段:
Field label = Link to doc
Field name = link_to_doc
Field type = Repeater
中继器子字段 1:
Field label = Link
Field name = link
Field type = Link
中继器子字段 2:
Field label = Text of link
Field name = text_of_link
Field type = Text
PHP代码:
<?php if ($section['link_to_doc']) : ?>
<?php foreach ($section['link_to_doc'] as $link) : ?>
<div>
<a href="<?= $link['link'] ?>" class="btn-txt">
<?= $link['text_of_link'] ?>
</a>
</div>
<?php endforeach; ?>
<?php endif; ?>
任何人都可以检查php代码并让我知道出了什么问题?
这个话题有一段时间没有答案,你可能已经找到了解决方案。 但是现在 ACF 正在解释如何直接在文档中访问嵌套转发器的数据。
<?php
// Loop over the first repeater
if( have_rows('type') ):
while( have_rows('type') ) : the_row();
// Loop over sub repeater rows.
if( have_rows('type') ):
while( have_rows('type') ) : the_row();
// Get sub value.
$child_title = get_sub_field('name');
endwhile;
endif;
endwhile;
endif;
还有其他方法可以访问此类数据,列表如下: https : //www.advancedcustomfields.com/resources/repeater/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.