ACF中继器字段没有结果


No Results from ACF Repeater Field

我有一个安装了ACF中继器字段的WordPress网站。我一直遵循视频教程,并在网站上尝试了每个版本的模板代码示例,但我根本无法显示任何内容,什么都没有。

我的中继器字段名为"carousel_images",它有3个子字段,"image"、"headline"answers"text"。

有人能帮忙吗?我只想在主页的前端显示这些字段,这是一个使用"frontpage.php"模板的静态页面。

我的代码:

<?php if(get_field('carousel_images')): ?>
    <div>
        <?php while(has_sub_field('carousel_images')): ?>
            <img src="<?php the_sub_field('image'); ?>">
            <div class="caption">
                <h3><?php the_sub_field('headline'); ?></h3>
                <p><?php the_sub_field('text'); ?></p>
                <a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
                <a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></a>
            </div>
        <?php endwhile; ?>
    </div>
<?php endif; ?>

编辑1我的中继器字段位于自定义帖子类型内,因此在尝试显示中继器字段之前,我必须使用WP_Query来显示自定义帖子类型。修改了以下工作规范。

再次感谢。

<?php
    $args = array(
        'post_type' => 'home_carousel_image'
    );
    $the_query = new WP_Query( $args );
?>

<!-- WP_Query WordPress loop -->
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <?php if(get_field('carousel_images')): ?>
        <?php while(has_sub_field('carousel_images')): ?>
        <div>
            <img src="<?php the_sub_field('image'); ?>">
            <div class="caption">
                <h3><?php the_sub_field('headline'); ?></h3>
                <p><?php the_sub_field('text'); ?></p>
                <a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
                <a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></span></a>
            </div>
        </div>
        <?php endwhile; ?>
    <?php endif; ?>
<?php endwhile; else: ?>
    <!-- Displayed if no posts or pages are available -->
    <p>There are no posts or pages here!</p>
<?php endif; ?>

我的中继器字段位于自定义帖子类型内,因此在尝试显示中继器字段之前,我必须使用WP_Query来显示自定义帖子类型。修改了以下工作规范。

再次感谢。

<?php
    $args = array(
        'post_type' => 'home_carousel_image'
    );
    $the_query = new WP_Query( $args );
?>

<!-- WP_Query WordPress loop -->
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <?php if(get_field('carousel_images')): ?>
        <?php while(has_sub_field('carousel_images')): ?>
        <div>
            <img src="<?php the_sub_field('image'); ?>">
            <div class="caption">
                <h3><?php the_sub_field('headline'); ?></h3>
                <p><?php the_sub_field('text'); ?></p>
                <a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
                <a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></span></a>
            </div>
        </div>
        <?php endwhile; ?>
    <?php endif; ?>
<?php endwhile; else: ?>
    <!-- Displayed if no posts or pages are available -->
    <p>There are no posts or pages here!</p>
<?php endif; ?>

您的中继器不正确。中继器是一排。

<?php if (have_rows('carousel_images')): ?>
    <div>
        <?php while (have_rows('carousel_images')): the_row(); ?>
            <img src="<?php the_sub_field('image'); ?>">
            <div class="caption">
                <h3><?php the_sub_field('headline'); ?></h3>
                <p><?php the_sub_field('text'); ?></p>
                <a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
                <a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></a>
            </div>
        <?php endwhile; ?>
    </div>
<?php endif; ?>