title: ACF - Looping thru posts, then thru flexible content, then thru repeater
body: <p>What I am trying to do is get images from a repeater field and fill my homepage with images that lead to posts. </p>
  
  <p>This is usually easy for me but the catch here is that there are multiple images for each post in a repeater field, which are in a flexible content field of the advanced custom fields plugin.</p>
  
  <p>The goal is to have an unlimited amount of images coming from the 'square_image' field in completely random order on the homepage that lead to their particular post. So with 15 posts that each have 15 'square_images' there would be 225 images on the homepage in completely random placement linking to their respective posts.</p>
  
  <p>I am wondering if I need to build an array inside the while loops so that I can get that ultimate random order at the end, instead of just the first 15 images from post 1 in random order, and then the next 15 images from post 2 in a random order which is not what i am trying to do.</p>
  
  <pre><code>&lt;?php get_header(); /* Template Name: Homepage Looper */ ?&gt;
  &lt;div id="homepage"&gt;
  &lt;?php 
  // the query
  $args = array(
              'post_type' =&gt; 'projects',
              'posts_per_page' =&gt; '-1',
              'orderby' =&gt; 'rand',
          );
  $the_query = new WP_Query( $args );$count = 1; ?&gt;
  
  &lt;?php if ( $the_query-&gt;have_posts() ) : ?&gt;
  &lt;div class="row"&gt;
    &lt;!-- the loop --&gt;
    &lt;?php 
  
      while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post();
        if( have_rows('the_page_content') ):
          while ( have_rows('the_page_content') ) : the_row();
            if(get_sub_field('images')) :
  
              while(has_sub_field('images')) : the_row();
  
    ?&gt;
              &lt;?php 
            $image = get_sub_field('square_image');
        if ( !empty($image) ): 
          // vars
          $url = $image['url'];
          $title = $image['title'];
          $alt = $image['alt'];
      ?&gt;
         &lt;div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 home-tile-holder"&gt;
            &lt;a href="&lt;?php the_permalink(); ?&gt;" rel="&lt;?php the_title(); ?&gt;"&gt;
                &lt;img src="&lt;?php echo $url; ?&gt;" alt="&lt;?php echo $alt; ?&gt;" class="img-responsive home-tile" /&gt;
                &lt;span class="title"&gt;&lt;?php the_title(); ?&gt;&lt;br&gt;&lt;img src="&lt;?php echo get_stylesheet_directory_uri(); ?&gt;/img/magnify.png"&gt;&lt;/span&gt;
            &lt;/a&gt;
         &lt;/div&gt;
      &lt;?php endif; ?&gt;
  &lt;?php 
  if($count % 6 == 0) {echo '&lt;/div&gt;&lt;div class="row"&gt;';}
  $count++;
    ?&gt;
  
    &lt;?php
    endwhile; //  while(has_sub_field('images')
    endif; //     get_sub_field('images')
    endwhile; //  have_rows('the_page_content')
    endif; //     have_rows('the_page_content')
    endwhile; //  $the_query-&gt;have_posts ?&gt;
    &lt;!-- end of the loop --&gt;
  
    &lt;/div&gt;
  
    &lt;?php wp_reset_postdata(); ?&gt;
  
  &lt;?php else:  ?&gt;
    &lt;p&gt;&lt;?php _e( 'Sorry, no posts matched your criteria.' ); ?&gt;&lt;/p&gt;
  &lt;?php endif; // $the_query-&gt;have_posts ?&gt;
  &lt;/div&gt;
  &lt;div id="single_project" style="position: absolute; margin-left:100%; width:100%;"&gt;
  
  &lt;/div&gt;
  &lt;?php get_footer(); ?&gt;
  </code></pre>
  
  <p>THE ACF EXPORT IS BELOW</p>
  
  <pre><code>if(function_exists("register_field_group"))
  {
  register_field_group(array (
          'id' =&gt; 'acf_project-fields',
          'title' =&gt; 'Project Fields',
          'fields' =&gt; array (
              array (
                  'key' =&gt; 'field_534efd890cd30',
                  'label' =&gt; 'Hero Image',
                  'name' =&gt; 'hero_image',
                  'type' =&gt; 'image',
                  'instructions' =&gt; 'Upload the large version for this post     that will be used as the hero image on the top of the page.',
                  'save_format' =&gt; 'url',
                  'preview_size' =&gt; 'thumbnail',
              'library' =&gt; 'all',
          ),
          array (
              'key' =&gt; 'field_534efdb70cd31',
              'label' =&gt; 'Page Content',
              'name' =&gt; 'the_page_content',
              'type' =&gt; 'flexible_content',
              'instructions' =&gt; 'Build out the content for this project.',
              'layouts' =&gt; array (
                  array (
                      'label' =&gt; 'Image Row',
                      'name' =&gt; 'image_row',
                      'display' =&gt; 'row',
                      'min' =&gt; '',
                      'max' =&gt; '',
                      'sub_fields' =&gt; array (
                          array (
                              'key' =&gt; 'field_534efdea0cd32',
                              'label' =&gt; 'Images',
                              'name' =&gt; 'images',
                              'type' =&gt; 'repeater',
                              'column_width' =&gt; '',
                              'sub_fields' =&gt; array (
                                  array (
                                      'key' =&gt; 'field_53716523cfc52',
                                      'label' =&gt; 'Square Image',
                                      'name' =&gt; 'square_image',
                                      'type' =&gt; 'image',
                                      'column_width' =&gt; '',
                                      'save_format' =&gt; 'object',
                                      'preview_size' =&gt; 'thumbnail',
                                      'library' =&gt; 'all',
                                  ),
                                  array (
                                      'key' =&gt; 'field_53716532cfc53',
                                      'label' =&gt; 'Full Size Image',
                                      'name' =&gt; 'full_size_image',
                                      'type' =&gt; 'image',
                                      'column_width' =&gt; '',
                                      'save_format' =&gt; 'object',
                                      'preview_size' =&gt; 'thumbnail',
                                      'library' =&gt; 'all',
                                  ),
                              ),
                              'row_min' =&gt; 1,
                              'row_limit' =&gt; 6,
                              'layout' =&gt; 'table',
                              'button_label' =&gt; 'Add Image Set',
                          ),
                      ),
                  ),
                  array (
                      'label' =&gt; 'Text + Images',
                      'name' =&gt; 'text_images',
                      'display' =&gt; 'row',
                      'min' =&gt; '',
                      'max' =&gt; '',
                      'sub_fields' =&gt; array (
                          array (
                              'key' =&gt; 'field_5356d3a6a8ac9',
                              'label' =&gt; 'Title',
                              'name' =&gt; 'title',
                              'type' =&gt; 'text',
                              'instructions' =&gt; 'Enter in the title of this project if you wish for it to show above the text.',
                              'column_width' =&gt; '',
                              'default_value' =&gt; '',
                              'placeholder' =&gt; '',
                              'prepend' =&gt; '',
                              'append' =&gt; '',
                              'formatting' =&gt; 'html',
                              'maxlength' =&gt; '',
                          ),
                          array (
                              'key' =&gt; 'field_534eff4ae5d31',
                              'label' =&gt; 'Text Content',
                              'name' =&gt; 'text_content',
                              'type' =&gt; 'wysiwyg',
                              'column_width' =&gt; '',
                              'default_value' =&gt; '',
                              'toolbar' =&gt; 'full',
                              'media_upload' =&gt; 'yes',
                          ),
                          array (
                              'key' =&gt; 'field_534eff32e5d30',
                              'label' =&gt; 'Images',
                              'name' =&gt; 'images',
                              'type' =&gt; 'repeater',
                              'column_width' =&gt; '',
                              'sub_fields' =&gt; array (
                                  array (
                                      'key' =&gt; 'field_53716549cfc54',
                                      'label' =&gt; 'Square Image',
                                      'name' =&gt; 'square_image',
                                      'type' =&gt; 'image',
                                      'column_width' =&gt; '',
                                      'save_format' =&gt; 'object',
                                      'preview_size' =&gt; 'thumbnail',
                                      'library' =&gt; 'all',
                                  ),
                                  array (
                                      'key' =&gt; 'field_53716557cfc55',
                                      'label' =&gt; 'Full Size Image',
                                      'name' =&gt; 'full_size_image',
                                      'type' =&gt; 'image',
                                      'column_width' =&gt; '',
                                      'save_format' =&gt; 'object',
                                      'preview_size' =&gt; 'thumbnail',
                                      'library' =&gt; 'all',
                                  ),
                              ),
                              'row_min' =&gt; '',
                              'row_limit' =&gt; 3,
                              'layout' =&gt; 'table',
                              'button_label' =&gt; 'Add Image Set',
                          ),
                      ),
                  ),
                  array (
                      'label' =&gt; 'Images + Text',
                      'name' =&gt; 'images_text',
                      'display' =&gt; 'row',
                      'min' =&gt; '',
                      'max' =&gt; '',
                      'sub_fields' =&gt; array (
                          array (
                              'key' =&gt; 'field_534effafb045d',
                              'label' =&gt; 'Images',
                              'name' =&gt; 'images',
                              'type' =&gt; 'repeater',
                              'column_width' =&gt; '',
                              'sub_fields' =&gt; array (
                                  array (
                                      'key' =&gt; 'field_53716567cfc56',
                                      'label' =&gt; 'Square Image',
                                      'name' =&gt; 'square_image',
                                      'type' =&gt; 'image',
                                      'column_width' =&gt; '',
                                      'save_format' =&gt; 'object',
                                      'preview_size' =&gt; 'thumbnail',
                                      'library' =&gt; 'all',
                                  ),
                                  array (
                                      'key' =&gt; 'field_53716576cfc57',
                                      'label' =&gt; 'Full Size Image',
                                      'name' =&gt; 'full_size_image',
                                      'type' =&gt; 'image',
                                      'column_width' =&gt; '',
                                      'save_format' =&gt; 'object',
                                      'preview_size' =&gt; 'thumbnail',
                                      'library' =&gt; 'all',
                                  ),
                              ),
                              'row_min' =&gt; '',
                              'row_limit' =&gt; 3,
                              'layout' =&gt; 'table',
                              'button_label' =&gt; 'Add Image Set',
                          ),
                          array (
                              'key' =&gt; 'field_5356d3dba8aca',
                              'label' =&gt; 'Title',
                              'name' =&gt; 'title',
                              'type' =&gt; 'text',
                              'instructions' =&gt; 'Enter in the title of this project if you wish for it to show above the text.',
                              'column_width' =&gt; '',
                              'default_value' =&gt; '',
                              'placeholder' =&gt; '',
                              'prepend' =&gt; '',
                              'append' =&gt; '',
                              'formatting' =&gt; 'html',
                              'maxlength' =&gt; '',
                          ),
                          array (
                              'key' =&gt; 'field_534effafb045c',
                              'label' =&gt; 'Text Content',
                              'name' =&gt; 'text_content',
                              'type' =&gt; 'textarea',
                              'column_width' =&gt; '',
                              'default_value' =&gt; '',
                              'placeholder' =&gt; '',
                              'maxlength' =&gt; '',
                              'rows' =&gt; '',
                              'formatting' =&gt; 'br',
                          ),
                      ),
                  ),
              ),
              'button_label' =&gt; 'Add Row',
              'min' =&gt; '',
              'max' =&gt; '',
          ),
      ),
      'location' =&gt; array (
          array (
              array (
                  'param' =&gt; 'post_type',
                  'operator' =&gt; '==',
                  'value' =&gt; 'projects',
                  'order_no' =&gt; 0,
                  'group_no' =&gt; 0,
              ),
          ),
      ),
      'options' =&gt; array (
          'position' =&gt; 'normal',
          'layout' =&gt; 'no_box',
          'hide_on_screen' =&gt; array (
              0 =&gt; 'the_content',
              1 =&gt; 'excerpt',
              2 =&gt; 'custom_fields',
              3 =&gt; 'discussion',
              4 =&gt; 'comments',
              5 =&gt; 'format',
              6 =&gt; 'featured_image',
              7 =&gt; 'send-trackbacks',
          ),
      ),
      'menu_order' =&gt; 0,
  ));
  }
  </code></pre>