如何一一获取ACF转发器字段值?

时间:2018-09-15 18:18:45

标签: php wordpress advanced-custom-fields acfpro

我正在使用ACF pro中继器创建表列表。我想分别获取每一行。

如何分别获取每一行的值?

这是我的代码:

<?php if( have_rows('depleted_nutrients', 153) ):
        while( have_rows('depleted_nutrients', 153) ): the_row(); ?>

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

        <?php endwhile; ?>
<?php endif; ?>

预先感谢您的回答。

1 个答案:

答案 0 :(得分:0)

由于某种原因,您的示例也对我不起作用-建议使用ACF ...(很奇怪)。

我总是使用下面的方法-调用对象,然后调用每个单独的对象并获取其参数。

$rows = get_field('repeater_field_name');
if($rows)
{
    echo '<ul>';

    foreach($rows as $row)
    {
        echo '<li>sub_field_1 = ' . $row['sub_field_1'] . ', sub_field_2 = ' . $row['sub_field_2'] .', etc</li>';
    }

    echo '</ul>';
}

来源:https://www.advancedcustomfields.com/resources/repeater/

相关问题