【问题标题】:Acf checkbox in acf repeater change classacf 中继器更改类中的 Acf 复选框
【发布时间】:2019-10-30 02:13:40
【问题描述】:

我想在中继器中选择复选框时更改类。我使用switch case 执行此操作,但我无法获得while 之外的支票簿值。如何正确地从while 中取出复选框数组?

ACF

$checkboxarray = get_field('sy_color');

代码:

<div class="loop solution-include-pages d-flex">
    <?php
    if (have_rows('support_you')) {
        $checkboxarray = get_field('sy_color');
        foreach ($checkboxarray as $value) {
            switch ($value) {
                case 'red':
                    $class = 'rose-c';
                    break;
                case 'green':
                    $class = 'green-c';
                    break;
                case 'blueberry':
                    $class = 'blueberry-c';
                    break;
            }
            while (have_rows('support_you')) {
                the_row();
                $sy_img = get_sub_field('sy_img');
                $sol_img = wp_get_attachment_image_src( $sy_img, 'full', true );
                $sy_header = get_sub_field('sy_header');
                $sy_content = get_sub_field('sy_content');
                $sy_link = get_sub_field('sy_link');
                $sy_color = get_sub_field('sy_color');
    ?>
    <div class="sol-item d-flex flex-direction">
        <div class="sol-item-img">
            <img src="<?php echo $sol_img[0];?>" class="img-responsive" alt="">
        </div>
        <div class="sol-content">
            <div class="sol-content-header <?php echo $class; ?>">
                <?php echo $sy_header; ?>
            </div>
            <div class="sol-content-text">
                <?php echo $sy_content; ?>
            </div>
            <a href="<?php echo $sy_link;?>" class="bluberry-btn item-center">Learn more</a>
        </div>
    </div>
    <?php
    }
    }
    }
    ?>
</div>

Acf 支票选项:

【问题讨论】:

  • 如果复选框在中继器内,则应使用get_sub_field() 而不是get_field()

标签: wordpress advanced-custom-fields


【解决方案1】:

如果你不在 the_row();您无法获得子字段。如果您使用

将字段“support_you”分配给变量
$support_you = get_field('support_you');

它将返回一个数组数组,所有子字段都将在该数组中返回,您可以通过这种方式访问​​它。查看返回的结构的一个好方法是像这样将数组回显到屏幕上

echo '<pre>', print_r( $support_you, 1 ), '</pre>';

【讨论】:

  • 感谢您的帮助,在输出所有数组后,我弄清楚并正确设置了条件
猜你喜欢
  • 2018-04-02
  • 1970-01-01
  • 1970-01-01
  • 2021-04-13
  • 2021-03-07
  • 2019-02-03
  • 2017-01-29
  • 2013-08-05
  • 1970-01-01
相关资源
最近更新 更多