-
-
Save dancywritter/a6a8a1cd304eb057cff2dd9968b44739 to your computer and use it in GitHub Desktop.
Creating objects using ACF repeater fields #wordpress #acf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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