短码显示嵌套的ACF中继器字段。

问题描述 投票:0回答:1

在Wordpress中,为了显示一个嵌套的中继器ACF字段,我在php中改编了几行代码,插入到帖子的存档页中。在存档中,硬代码运行得很好,代码创建的行数也显示得很好。我需要通过Elementor来使用这段代码。要做到这一点,我需要创建一个短码。我用代码创建了一个短码。什么运行良好,什么都不显示,甚至当我取消激活Elementor可以你,请帮助我,布鲁诺这是代码。

function acf2repeaters_ingredients_function() {
    while ( have_posts() ) : the_post();
        // check for rows (parent repeater)
        if( have_rows('en-tete_ingredients') ): ?>
            <div id="en-tete_ingredients">
                <?php // loop through rows (parent repeater) 
                while( have_rows('ingredients') ): the_row(); ?>
                    <div>
                        <h3><?php the_sub_field('en-tete_ingredients'); ?></h3>
                        <?php // check for rows (sub repeater)
                        if( have_rows('liste_des_ingredients') ): ?>
                            <ul>
                                <?php // loop through rows (sub repeater)
                                while( have_rows('ingredients') ): the_row(); ?>
                                    <li <?php echo ' class="nombre"'; ?>><?php the_sub_field('quantite');?></li>
                                    <li <?php echo ' class="unite"'; ?>><?php the_sub_field('unite');?></li>
                                    <li <?php echo ' class="ingredient"'; ?>><?php the_sub_field('ingredient');?></li>
                                <?php endwhile; ?>
                            </ul>
                        <?php endif; //if( get_sub_field('ingredients') ): ?>
                    </div>
                <?php endwhile; // while( has_sub_field('en-tete_ingredients') ): ?>
            </div>
        <?php endif; // if( get_field('en-tete_ingredients') )
    endwhile; // end of the loop.
}
add_shortcode( 'acf2repeaters_ingredients', 'acf2repeaters_ingredients_function' );
php wordpress shortcode acfpro
1个回答
0
投票

解决办法 删除这一行: while ( have_posts() ) : the_post()移除这一行: endwhile; // end of the loop. 然后,短码摇滚!

© www.soinside.com 2019 - 2024. All rights reserved.