Title: Image attachment repeater
Last modified: February 5, 2019

---

# Image attachment repeater

 *  Resolved [sgroup](https://wordpress.org/support/users/sgroup/)
 * (@sgroup)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/image-attachment-repeater/)
 * Hi,
 * I have a form with a file upload field and I made a function to attach the uploaded
   file before sending the email. It looks like this:
 *     ```
       function filter_email_attachments( $attachments, $email, $form, $fields ) {
           $file = af_get_field( 'file' );
           $filedir = get_attached_file( $file );
           $attachments[] = $filedir;
           return $attachments;
       }
       add_filter( 'af/form/email/attachments/key=form_2c348ef543a81', 'filter_email_attachments', 10, 4 );
       ```
   
 * This works great, but I was wondering if it is possible to use a repeater field,
   so a user can upload multiple files. How can I attach multiple files to my function?
 * Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [fabianlindfors](https://wordpress.org/support/users/fabianlindfors/)
 * (@fabianlindfors)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/image-attachment-repeater/#post-11177588)
 * Hi!
 * If you use `af_get_field` with a repeater you’ll get all the rows. As such you
   should be able to add them all like this:
 *     ```
       function filter_email_attachments( $attachments, $email, $form, $fields ) {
           $repeater = af_get_field( 'REPEATER_FIELD_NAME' );
           foreach ( $repeater as $row ) {
              $file = $row['file'];
              $filedir = get_attached_file( $file );
              $attachments[] = $filedir;
           }
   
           return $attachments;
       }
       add_filter( 'af/form/email/attachments/key=form_2c348ef543a81', 'filter_email_attachments', 10, 4 );
       ```
   
 * Change REPEATER_FIELD_NAME to whatever your repeater is called. Also, possibly
   change the name in the loop if you subfield is not called “file”.
 * Hope this helps!
 *  Thread Starter [sgroup](https://wordpress.org/support/users/sgroup/)
 * (@sgroup)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/image-attachment-repeater/#post-11183029)
 * Works great, thanks!
 *  Thread Starter [sgroup](https://wordpress.org/support/users/sgroup/)
 * (@sgroup)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/image-attachment-repeater/#post-11735716)
 * Hi, after plugin update this no longer seems to work. Any idea?
 * Thanks!
 *  Plugin Author [fabianlindfors](https://wordpress.org/support/users/fabianlindfors/)
 * (@fabianlindfors)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/image-attachment-repeater/#post-11737875)
 * Hi!
 * Which update are you referring to?
 *  Thread Starter [sgroup](https://wordpress.org/support/users/sgroup/)
 * (@sgroup)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/image-attachment-repeater/#post-11739106)
 * Hi,
 * I’ve updated the plugin from version 1.6.0 (which worked perfectly) to 1.6.4

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Image attachment repeater’ is closed to new replies.

 * ![](https://ps.w.org/advanced-forms/assets/icon-256x256.png?rev=1894254)
 * [Advanced Forms for ACF](https://wordpress.org/plugins/advanced-forms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-forms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-forms/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-forms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-forms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-forms/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [sgroup](https://wordpress.org/support/users/sgroup/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/image-attachment-repeater/#post-11739106)
 * Status: resolved