簡體   English   中英

Wordpress ACF 中繼器子字段

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM