【问题标题】:ACF Repeater field not seeing rowsACF 中继器字段看不到行
【发布时间】:2015-03-30 12:32:28
【问题描述】:

有一个转发器字段,用于查看节类型是什么,然后输出基于该类型的特定代码。出于某种原因,即使有行,代码也总是输出“No Rows Found”。

我已经将它用于其他用途,但想再次使用它来输出不同的东西它不起作用。

下面是代码

<?php if( have_rows('layout_section') ): ?>

    <?php while(the_repeater_field('layout_section')): ?>

        <?php if (get_sub_field('layout_section_type') == "test") { ?>

            <?php the_sub_field('post_id'); ?>

        <?php } elseif ( get_sub_field('layout_section_type') == "featured" ) { ?>

            <p>Featured Section</p>

        <?php } elseif ( get_sub_field('layout_section_type') == "test2" ) { ?>

            <p>Tewsat 2</p>


        <?php } else { ?>

            <p>Normal Section</p>

        <?php } ?>

    <?php endwhile; ?>

<?php
else :
    echo 'No Rows Found';
    // no rows found
endif;
?>

这是 ACF 端的配置

http://i.stack.imgur.com/SbHDp.png http://i.stack.imgur.com/7zvP3.png

【问题讨论】:

    标签: php wordpress advanced-custom-fields


    【解决方案1】:

    您的代码看起来与 ACF 网站上的示例代码不同:

    http://www.advancedcustomfields.com/resources/repeater/

    尝试将您的 while 换成以下内容:

    while ( have_rows('layout_section') ) : the_row();
    

    【讨论】:

    • 是的,我也尝试过这种方式,但没有成功。我有另一个转发器字段的另一个文件,代码工作正常。除了字段和子字段之外,此代码相同。我已经检查以确保字段名称等都正确,并且我没有看到任何错误。
    • 可能值得检查一下配置和选项页面中的选项设置是否正常?
    • 查看了设置,但看不到任何不合适的地方。已将我的问题更新为带有设置图像的链接。似乎无法弄清楚为什么已经有效的确切代码不适用于另一个自定义部分。
    猜你喜欢
    • 2018-04-11
    • 2019-03-30
    • 2017-01-01
    • 2019-10-16
    • 2015-02-17
    • 1970-01-01
    • 2014-09-22
    • 2018-07-17
    • 2016-12-07
    相关资源
    最近更新 更多