Support

Account

Home Forums Add-ons Repeater Field Trouble retrieving File URL in Repeater Field Reply To: Trouble retrieving File URL in Repeater Field

  • sorry, prematurely submitted that. Let’s try again.

    I set up a field group using the code as a reference and inserted your code into the template without making any changes to it. The result of my test is here: http://www.ssird7.com.php53-14.dfw1-2.websitetestlink.com/2015/08/18/hello-world/ and it’s working for me.

    Here is the exported field group I created:

    
    <?php 
    
    if(function_exists("register_field_group"))
    {
      register_field_group(array (
        'id' => 'acf_test-group',
        'title' => 'test group',
        'fields' => array (
          array (
            'key' => 'field_56aaccc8f9a22',
            'label' => 'downloads',
            'name' => 'downloads',
            'type' => 'repeater',
            'sub_fields' => array (
              array (
                'key' => 'field_56aacd07f9a23',
                'label' => 'downloads_title',
                'name' => 'downloads_title',
                'type' => 'text',
                'column_width' => '',
                'default_value' => '',
                'placeholder' => '',
                'prepend' => '',
                'append' => '',
                'formatting' => 'html',
                'maxlength' => '',
              ),
              array (
                'key' => 'field_56aacd10f9a24',
                'label' => 'documents',
                'name' => 'documents',
                'type' => 'repeater',
                'column_width' => '',
                'sub_fields' => array (
                  array (
                    'key' => 'field_56aacd30f9a25',
                    'label' => 'document_upload',
                    'name' => 'document_upload',
                    'type' => 'file',
                    'column_width' => '',
                    'save_format' => 'object',
                    'library' => 'all',
                  ),
                  array (
                    'key' => 'field_56aaceeb47f43',
                    'label' => 'document_name',
                    'name' => 'document_name',
                    'type' => 'text',
                    'column_width' => '',
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'formatting' => 'html',
                    'maxlength' => '',
                  ),
                ),
                'row_min' => '',
                'row_limit' => '',
                'layout' => 'row',
                'button_label' => 'Add Row',
              ),
            ),
            'row_min' => '',
            'row_limit' => '',
            'layout' => 'row',
            'button_label' => 'Add Row',
          ),
        ),
        'location' => array (
          array (
            array (
              'param' => 'post_type',
              'operator' => '==',
              'value' => 'post',
              'order_no' => 0,
              'group_no' => 0,
            ),
          ),
        ),
        'options' => array (
          'position' => 'normal',
          'layout' => 'no_box',
          'hide_on_screen' => array (
          ),
        ),
        'menu_order' => 0,
      ));
    }
    
    

    and here is the code in the template, which is just a copy of yours

    
    if( have_rows('downloads') ): ?>
      
      <div id="downloads">
        <?php
          // loop through rows (parent repeater)
          while( have_rows('downloads') ): the_row();
        ?>
        
        <div class="downloads-title">
          <h3><?php the_sub_field('downloads_title'); ?></h3>
          <i class="downloads-border"></i>
          
          <?php
            // check for rows (sub repeater)
            if( have_rows('documents') ):
          ?>
            
          <ul class="fa-ul">
            <?php
              // loop through rows (sub repeater)
              while( have_rows('documents') ): the_row();
            
              // display each item as a list - with a class of completed ( if completed )
              $file = get_sub_field('document_upload'); 
            ?>
            
            <li><i class="fa-li fa fa-download"></i><a href="<?php echo $file['url']; ?>"><?php the_sub_field('document_name'); ?></a></li>
            
            <?php endwhile; ?>
          </ul>
          
          <?php endif; //if( get_sub_field('documents') ): ?>
        </div>
        <?php endwhile; // while( have_rows('downloads') ): ?>
      </div>
    <?php endif;