I want to create a shortcode using ACF Repeater Field and so I’ve found this code and when I tried to apply it on my website it doesn’t work. Am using genesis frame work.
my aim is create a shortcode using ACF Repeater Field and display table in post or page.
Here is my code in functions.php:
function menu_loop () {
echo '<div class="entry-content dishes">';
// check if the repeater field has rows of data
if( have_rows('menu_sections') ):
// loop through the rows of data
while ( have_rows('menu_sections') ) : the_row();
// display a sub field value
echo '<h2>' . get_sub_field('section_title') . '</h2>';
if ( have_rows('sections_items'));?>
<table>
<thead>
<tr>
<td class="ja_name">Name</td>
<td class="ja_description">Description</td>
<td class="ja_price">Price</td>
</tr>
</thead>
<?php while (have_rows('section_items') ): the_row(); ?>
<tr>
<td><?php the_sub_field('dish_names'); ?></td>
<td><?php the_sub_field('dish_description'); ?></td>
<td>$ <?php the_sub_field('dish_price'); ?></td>
</tr>
<?php endwhile;?>
</table> <?php
endwhile;
else :
// no rows found
endif; ?></div>
add_shortcode('testimonials', 'menu_loop');