Title: Custom addon &#8211; multiple image import
Last modified: July 11, 2018

---

# Custom addon – multiple image import

 *  Resolved [logicred](https://wordpress.org/support/users/logicred/)
 * (@logicred)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/custom-addon-multiple-image-import/)
 * I have written an XML addon which takes a single image from my feed using your
   documentation example and it works great!:
 * $my_addon->add_field( ‘property_featured_img’, ‘Property Featured Image’, ‘image’);
 * I can extract the attachment_id for my plugin perfectly using this:
 * $attachment_id = $data[‘property_featured_img’][‘attachment_id’];
 * I would now like to import multiple images, but am not clear how to extract the
   attachment_id number from each one using the example you give below.
 * $my_addon->import_images( ‘property_images’, ‘Property Images’ );
 * Ideally, I would like an array of attachment_id values of the images.
 * Thank you.

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

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/custom-addon-multiple-image-import/#post-10491704)
 * Hi [@logicred](https://wordpress.org/support/users/logicred/)
 * The “property_images” function in your example will receive three parameters:
   $post_id, $attachment_id, $filepath. Here’s an example of how you could add an
   array of the attachment IDs inside the “_my_custom_images” custom field:
 *     ```
       $my_addon->import_images( 'property_images', 'Property Images' );
   
       function property_images( $post_id, $attachment_id, $filepath ) {
           global $my_addon;
           $key = '_my_custom_images';
           $current_images = get_post_meta( $post_id, $key, true );
           if ( ! empty( $current_images ) ) {
               $current_images = maybe_unserialize( $current_images );
           } else {
               $current_images = array();
           }
   
           if ( ! in_array( $attachment_id, $current_images ) ) {
               $current_images[] = $attachment_id;
               update_post_meta( $post_id, $key, $current_images );
           }
       }
       ```
   
 * See also: [https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/pmxi_gallery_image.php](https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/pmxi_gallery_image.php).
 *  Thread Starter [logicred](https://wordpress.org/support/users/logicred/)
 * (@logicred)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/custom-addon-multiple-image-import/#post-10491781)
 * Perfect, thank you!

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

The topic ‘Custom addon – multiple image import’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [logicred](https://wordpress.org/support/users/logicred/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/custom-addon-multiple-image-import/#post-10491781)
 * Status: resolved