首页 > 解决方案 > archive.php 上带有画廊字段的 WordPress ACF 选项组返回 NULL

问题描述

我对archive.php 的ACF 有一个小问题。我有一个 ACF 组,其中包含一些字段。例如画廊领域。

问题是画廊字段返回NULL,有人知道如何解决这个问题吗?

这行代码有效并返回值。所以我不知道为什么画廊领域不起作用

<?php the_field('header_block_size', 'options');?>

这就是我想出的。

         <section id="page-header" class="page-header page-header--<?php the_field('header_block_size', 'options');?>">
            <?php $images = the_field('header_block_images', 'options'); ?>
            <?php var_dump($images);?>
            <?php if($images): ?>
                <div class="page-header__carousel">
                    <?php foreach($images as $image): ?>
                        <div class="page-header__inner" style="background-image: url('<?php echo esc_url($image) ?>')">
                        </div>
                    <?php endforeach; ?>
                </div>
                <div class="page-header__heading">
                        <h1 class="page-header__heading-title"><?php the_field('header_block_title', 'options');?></h1>
                        <div class="page-header__heading-border"></div>
                        <?php if(get_field('header_block_filter', 'options') === true): ?>
                            <div class="page-header__filter">
                                <?php echo do_shortcode('[searchandfilter fields="post_tag" submit_label="Check out the tours"]'); ?>
                            </div>
                        <?php endif;?>
                    </div>
            <?php endif ; ?>
        </section>

这是 ACF 组的位置设置

这是显示代码结果的图像,你可以看到它是 NULL

我希望有人知道如何解决这个问题。

提前致谢。

我用<?php var_dump(get_fields());?>代替编辑了代码<?php var_dump($images);?>,它返回array(1) { ["rating"]=> float(4) }

我还使用图库字段添加了一个新图像。

我添加到图库的内容的图片

标签: phpwordpressadvanced-custom-fields

解决方案


推荐阅读