Hey,
I´m trying to set up multiple Accordions with the repeater Field. Tried to do it with bootstrap accordions or selfmade accordions to make the markup easier, but content does not show on frontend either.
That´s my code so far
<?php
get_header();?>
<section id="about">
<div class="container">
<div class="row">
<div class="col-md-12 col-xs-12">
<?php
function accordion () {
//My ACF Fields for reference
//faqs - field group
//faq_question - sub-field
//faq_answer - sub-field
// check if the repeater field has rows of data
if( have_rows('faqs') ):
// loop through the rows of data
while ( have_rows('faqs') ) : the_row();
// display a sub field value
echo'<div id="faq_container">
<div class="faq">
<div class="faq_question"> <span class="question">' . get_sub_field('faq_question') . '</span><span class="accordion-button-icon fa fa-plus"></span></div>
<div class="faq_answer_container">
<div class="faq_answer"><span>' . get_sub_field('faq_answer') . '</span></div>
</div>
</div>
</div>';
endwhile;
else :
// no rows found
endif;
}
?> </div>
</div>
</section>
<?php get_footer(); ?>
Hi @marc-k1205
You don’t need to put the whole thing in a function..
Remove the function wrapper 🙂
As a side note developer to developer you should really attempt to write readable code.. Look at this compared to the one you posted 🙂
<?php
//My ACF Fields for reference
//faqs - field group
//faq_question - sub-field
//faq_answer - sub-field
// check if the repeater field has rows of data
if( have_rows('faqs') ):
?>
<?php while ( have_rows('faqs') ) : the_row(); ?>
<div id="faq_container">
<div class="faq">
<div class="faq_question">
<span class="question"><?php the_sub_field('faq_question'); ?> </span>
<span class="accordion-button-icon fa fa-plus"></span>
</div>
<div class="faq_answer_container">
<div class="faq_answer">
<span><?php the_sub_field('faq_answer'); ?></span>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Hi Jonathan,
Thanks for your quick solution of my problem, it worked out fine and sorry for the code structure xD
No problem! We live and we learn!
Best of luck in your project.