Hi there, I am attempting to create a nested FAQ section whereby each ACF Section is a repeater and within that main section repeater, is the repeater for that sections questions. The problem I’m having is the answers section is outside of the loop for design purposes and I can’t think of any other way of getting the ACF data to that content section. The problem I’m having is not knowing how ACF works with PHP arrays and how I would be able to generate all instances of the content (answer blocks) when they’re outside the loop of the nested repeater.
My Code is as follows:
<section class="faq" aria-labelledby="faq-help"> <div class="container faq__container"> <?php // check for rows (parent repeater) if (have_rows('two_column_faq')): ?> <div class="faq__sidebar"> <?php // loop through rows (parent repeater) while (have_rows('two_column_faq')): the_row(); ?> <ul class="faq__sidebar--ul"> <h3><?php the_sub_field('faq_section_title'); ?></h3> <?php // check for rows (sub repeater) if (have_rows('faq_sub_heading')): ?> <?php // loop through rows (sub repeater) while (have_rows('faq_sub_heading')): the_row(); $questionArray = [ 'title' => get_sub_field('sub_heading_title'), 'content' => get_sub_field('faq_sub_heading_content') ] ?> <li class="faq__sidebar faq__sidebar__question" href="#faq2"> <span><?php the_sub_field('sub_heading_title'); ?></span></li> <?php endwhile; ?> <?php endif; //end items: ?> </ul> <?php endwhile; // while items exist ?> </div> <div id="faqContent" class="faq__content"> <h3> <?php echo $questionArray['title']; ?> </h3> <li class="faq__content faq__content__answer--active" id="faq1"> <p> <?php echo $questionArray['content']; ?></p> </li> </div> <?php endif; ?> </div> </section>
As it currently stands, the title of the question is reused from the question title and put into the right hand side of the screen for the title of the question above the answer. Then the answer is brought in from a set key value of [1) which is question 1, however I’m looking to dynamically pull in whatever question title and content there currently is.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!