Support

Account

Home Forums Add-ons Options Page Extract data from options page (repeater field)

Solving

Extract data from options page (repeater field)

  • Hi, I’m using flexible content with the repeater field for creating a FAQ section. Everything works fine and is displayed on the page edit page.

    I have created an options page and now I need to show the group of fields inside it. To extract the data inside the page (front end) I followed this guide:

    https://www.advancedcustomfields.com/resources/get-values-from-an-options-page/
    Below is the code I have developed.

    but without success. How can I solve?
    Thank you

    
    <?php
    // check if the flexible content field has rows of data
    if( have_rows('questions_frequent_flexible','option') ):
    $n_question;
      // loop through the rows of data
      while ( have_rows('questions_frequent_flexible','option') ) : the_row();
          if( get_row_layout() == 'section_faq' ):
            if( have_rows('list_faq_repeater') ):
              while( have_rows('list_faq_repeater') ): the_row();
              $n_question++;
    
                $section_faq_question = get_sub_field('question_repeater');
                $section_faq_answear = get_sub_field('answear_repeater');
                  ?>
    
                  <div class="accordion-item">
                    <h2 class="accordion-header" id="heading<?php echo $n_question; ?>">
                      <button type="button" class="accordion-button collapsed text-left" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $n_question; ?>">
                        <?php echo $n_question; ?>. <?php echo $section_faq_question;?>
                      </button>
                    </h2>
                    <div id="collapse<?php echo $n_question; ?>" class="accordion-collapse collapse text-left" data-bs-parent="#myAccordion">
                      <div class="card-body">
                        
                          <?php echo $section_faq_answear;?>
                        
    
                      </div>
                    </div>
                  </div>
    
                  <?php endwhile; ?>
                </div>
              <?php endif; ?>
               <?php endif;
      endwhile;
    else :
      // no layouts found
    endif;
    ?>
    
    
  • on everything you need the second parameter , ‘option’ if its an option field

  • Given your code I don’t see any reason it should not be working.

    What happens if you replace

    
    // no layouts found
    

    with

    
    echo 'no layouts found';
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.