Title: Export images as specific array
Last modified: April 1, 2020

---

# Export images as specific array

 *  Resolved [khvoroffski](https://wordpress.org/support/users/khvoroffski/)
 * (@khvoroffski)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/export-images-as-specific-array/)
 * Hi!
    I`m working on custom xml export, should be like this
 *     ```
       <?xml version="1.0" encoding="UTF-8"?>
       <Ads target="Avito.ru" formatVersion="3">
           <Ad>
               <Id>h632145</Id>
               <Category>Музыкальные инструменты</Category>
               <GoodsType>Гитары и другие струнные</GoodsType>
               <AdType>Товар приобретен на продажу</AdType>
               <Address>Москва, м. Речной вокзал</Address>
               <Title>Гитара Yamaha Pacifica</Title>
       		<Description><![CDATA[
               Гитара в очень хорошем состоянии, надёжная, прекрасный звук, есть едва заметные следы использования. Не Китай, сделана в Индонезии. Была у нас группа, распалась, поэтому некоторые инструменты оказались уже не нужны. Могу предложить вместе с гитарой: шнур 3 метра, фирменный широкий ремень, хороший чехол, а также комбоусилитель. Есть два громких усилителя. С одним (10 Вт) цена за всё 10500, с другим (15 Вт) - 12500.
               ]]></Description>
               <Price>8000</Price>
               <ManagerName>Менеджер по продажам</ManagerName>
               <AllowEmail>Да</AllowEmail>
               <Images>
                   <Image url="https://64.img.avito.st/640x480/4044040064.jpg"/>
                   <Image url="https://94.img.avito.st/640x480/4044040394.jpg"/>
                   <Image url="https://29.img.avito.st/640x480/4044040429.jpg"/>
                   <Image url="https://42.img.avito.st/640x480/4044040442.jpg"/>
                   <Image url="https://43.img.avito.st/640x480/4044040443.jpg"/>
               </Images>
       		<VideoURL>http://www.youtube.com/watch?v=YKmDXNrDdBI</VideoURL>
               <AdStatus>Free</AdStatus>
           </Ad>
       ```
   
 * I`m almost done, but there is a problem with images array, how can i put images
   in array like this –
 *     ```
               <Images>
                   <Image url="https://64.img.avito.st/640x480/4044040064.jpg"/>
                   <Image url="https://94.img.avito.st/640x480/4044040394.jpg"/>
                   <Image url="https://29.img.avito.st/640x480/4044040429.jpg"/>
                   <Image url="https://42.img.avito.st/640x480/4044040442.jpg"/>
                   <Image url="https://43.img.avito.st/640x480/4044040443.jpg"/>
               </Images>
       ```
   
 * And is it possible at all?

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

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/export-images-as-specific-array/#post-12635884)
 * Hi [@khvoroffski](https://wordpress.org/support/users/khvoroffski/)
 * You can use a PHP function to do that: [https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/](https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/).
   Here’s an example snippet that you can modify as needed:
 *     ```
       function my_output_images( $images ) {
       	$output = '<Images>';
       	if ( ! empty( $images ) ) {
       		if ( is_array( $images ) ) {
       			foreach ( $images as $img ) {
       				$output .= '<Image url="' . $img . '"/>';
       			}
       		} else {
       			$output .= '<Image url="' . $images . '">';
       		}
       	}
       	$output .= '</Images>';
       	return str_replace( array( '<', '>' ), array( '**LT**', '**GT**' ), $output );
       }
       ```
   
 * Example usage:
 * `[my_output_images({Image URL})]`
 * Just make sure you turn off CDATA tags when using functions to output data in
   custom XML exports: [https://d.pr/i/CsrTB9](https://d.pr/i/CsrTB9).
    -  This reply was modified 6 years, 1 month ago by [WP All Import](https://wordpress.org/support/users/wpallimport/).
    -  This reply was modified 6 years, 1 month ago by [WP All Import](https://wordpress.org/support/users/wpallimport/).
    -  This reply was modified 6 years, 1 month ago by [WP All Import](https://wordpress.org/support/users/wpallimport/).
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/export-images-as-specific-array/#post-12667225)
 * Hi [@khvoroffski](https://wordpress.org/support/users/khvoroffski/)
 * I am marking this as resolved since we haven’t heard back. Feel free to reply
   here if you still have questions about this issue. Anyone else please open a 
   new thread.
 *  Thread Starter [khvoroffski](https://wordpress.org/support/users/khvoroffski/)
 * (@khvoroffski)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/export-images-as-specific-array/#post-12677011)
 * Hello! Sorry for delay.
    Yes this is almost what needed, but i`m getting error`
   Warning: count(): Parameter must be an array or an object that implements Countable
   in ***/classes/XMLWriter.php on line 212` Do you know what can cause this error?
   It’s happen only when this code is active, so it`s all about those images (
 * And another question is – how to limit additional images generation (for example
   to 4 images maximum)?
    -  This reply was modified 6 years, 1 month ago by [khvoroffski](https://wordpress.org/support/users/khvoroffski/).
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/export-images-as-specific-array/#post-12693799)
 * Hi [@khvoroffski](https://wordpress.org/support/users/khvoroffski/)
 * > Do you know what can cause this error?
 * That’s fixed in the latest BETA of WP All Export and the fix will be included
   in the next release.
 * > And another question is – how to limit additional images generation (for example
   > to 4 images maximum)?
 * I’d suggest using array_slice() to extract the first 4 entries in the $images
   array right before the foreach loop: [https://www.php.net/manual/en/function.array-slice.php](https://www.php.net/manual/en/function.array-slice.php).

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

The topic ‘Export images as specific array’ is closed to new replies.

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

 * 4 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/export-images-as-specific-array/#post-12693799)
 * Status: resolved