Support

Account

Home Forums ACF PRO Flexible content inside a repeater field

Solving

Flexible content inside a repeater field

  • I did not find on your site and on google, the case of a flexible content inside a repeater.

    Unfortunately I can not recall correctly a flexible content that is filed inside a repeatable.

    A normal field flexibile activates a great time with foolish examples.

    flex_content = field type flex content
    1° element on flex content = flex_content_first_element
    sub field in to 1° element = flex_content_first_element_subfield
    2° element on flex content = flex_content_second_element
    sub field in to 2° element = flex_content_second_element_subfield

    if( have_rows('flex_content') ){
         // loop through the rows of data
        while ( have_rows('flex_content') ){ the_row();
            if( get_row_layout() == 'flex_content_first_element' ){
                  the_sub_field('flex_content_first_element_subfield');
             } 
            elseif( get_row_layout() == 'flex_content_second_element' ){ 
                  the_sub_field('flex_content_second_element_subfield');
            }
         }
    
    } else { }

    so everything is right. But if the value “field type flex content” was not top level but it is contained by a field riptetitore.
    What should I put in “have_rows (?)”

    I tried several attempts but do not function.
    So, you are the ultma beach ..

    I hope you know tell me the right one variable for this to work.

    Thank you!

  • You need to have nested loops for flex fields inside a repeater

    
    if (have_rows('repeater_field')) {
      while (have_rows('repeater_field')) {
        the_row();
        if (have_rows('flex_content_field')) {
          while (have_rows('flex_content_field')) {
            $layout = get_row_layout();
            // and the rest of your flex field output
          } // end second while have rows
        } // end second if have rows
      } // end first while have rows
    } // end first if have rows
    

    for more information see the nested loop section of this page http://www.advancedcustomfields.com/resources/have_rows/

  • thanks, now I understand the concept of recall.
    I had not thought because I usually use the foreach statement to retrieve reperater.

  • I looked back and saw that I forgot something important. My code above will create and infinite loop. Someday I should right a book on how to do it 😛

    
    if (have_rows('repeater_field')) {
      while (have_rows('repeater_field')) {
        the_row();
        if (have_rows('flex_content_field')) {
          while (have_rows('flex_content_field')) {
            the_row(); // forgot this line
            $layout = get_row_layout();
            // and the rest of your flex field output
          } // end second while have rows
        } // end second if have rows
      } // end first while have rows
    } // end first if have rows
    
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Flexible content inside a repeater field’ is closed to new replies.