Skip to content

Instantly share code, notes, and snippets.

@luclemo
Last active November 6, 2020 17:42
Show Gist options
  • Save luclemo/b540a2a25fdc81726d24 to your computer and use it in GitHub Desktop.
Save luclemo/b540a2a25fdc81726d24 to your computer and use it in GitHub Desktop.
Creating objects using ACF repeater fields #wordpress #acf
<?php
// check if the repeater field has rows of data
if( have_rows('drop-down_menus') ) :
$array = array(); // empty array, must be declared outside of while loop
$i = 0; // incrementer
// loop through the rows of data and add to our array
while ( have_rows('drop-down_menus') ) : the_row();
$array[$i]['title'] = get_sub_field('drop_down_title');
$array[$i]['content'] = get_sub_field('drop_down_content');
$i++;
endwhile;
echo count($array); // will return number of items in array
// now echo our html, cycling through our newly built array
foreach($array as $item) : ?>
<div class="accordion faq-section" data-accordion>
<div data-control><h4 class="title"><?php echo $item['title']; ?></h4></div>
<div data-content>
<div><?php echo $item['content']; ?></div>
</div>
</div>
<?php endforeach;
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment