【发布时间】:2019-03-30 02:06:22
【问题描述】:
我在 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 代码,让我知道哪里出了问题?
【问题讨论】:
-
在您的 if 语句中,您没有检查任何内容。尝试说“if(isset($section['link_to_doc'])”或检查它是否不为空。您也可以“var_dump”你的 $section 数组以查看它是否已设置。
-
另外,ACF 不返回数组,它返回对象,所以要访问它你需要说 $section->link_of_text
标签: php wordpress repeater advanced-custom-fields