In Wordpress, in order to display a nested repeater ACF field, I adapted a few lines in php that I insert in the archive page of post.
In the archive, the hard code runs very well and the lines created by the code are displayed as expected.
I need to use this code via Elementor. To do that, I need to create a shortcode.
I created a shortcode with the code.
Nothing runs good, nothing is displayed, even when I desactive Elementor
Can you, please, help me,
Bruno
Here is the code:
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' );