Title: Function that returns data in an array &#8211; Wp All Export &#8211;
Last modified: November 29, 2019

---

# Function that returns data in an array – Wp All Export –

 *  Resolved [K15Lmk98](https://wordpress.org/support/users/k15lmk98/)
 * (@k15lmk98)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/)
 * This is an automatic translation
 * Good day,
    I’m trying to return, with a personal function, an array of data. 
   But in the xml file they are not decoded and show: <Image> Array </ image> <Image
   > Array </ image> ……
 * FUNCTION
 *     ```
       function cr_get_images($id) {    	
       	$gallery_list = get_post_meta($id, '_gallery', true );	
       	$array_data = array();
       	foreach ($gallery_list as $key =>$value) :
       		$array_data[] = array('image'=>$value, 'alttext'=>$key);
       	endforeach;	
       	return $array_data;   
       }
       ```
   
 * CALL
    `<image>[cr_get_images({ID})]</image>`
 * I tried to pass serialized data with:
    `return serialize($array_data);` but in
   the xml file they are not deserialized
 * How can I pass an associative array of data like this to a custom XML file, using
   the Wp All Export editor?
    `$array_data[] = array('image'=>$value, 'alttext'=
   >$key);`
 * Thanks, Claudio_

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

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12190052)
 * Hi [@k15lmk98](https://wordpress.org/support/users/k15lmk98/)
 * > How can I pass an associative array of data like this to a custom XML file,
   > using the Wp All Export editor?
 * It depends on how you’re wanting to display the data. Can you show me a manually
   created example of the XML output you’re looking for? For example, if the array
   contained this:
 *     ```
       $array_data = array(
           array(
               'image' => 'img1.jpg',
               'alttext' => 'text1'
           ),
           array(
               'image' => 'img2.jpg',
               'alttext' => 'text2'
           ),
           array(
               'image' => 'img3.jpg',
               'alttext' => 'text3'
           ),
       );
       ```
   
 * What should the XML output look like?
 *  Thread Starter [K15Lmk98](https://wordpress.org/support/users/k15lmk98/)
 * (@k15lmk98)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12190248)
 * Hi,
    actually I found the solution by reading the ticket: [https://wordpress.org/support/topic/export-images-as-nested-elements/](https://wordpress.org/support/topic/export-images-as-nested-elements/)
 * **However there is a problem**.
    If I make the Preview in the editor I see the
   correct nodes:
 *     ```
       <images>
       <image number="1">
       <image>
       https://www.dreamvillas.estate/wp-content/uploads/2019/09/11/Historical-Villa-Lake-Como-45.jpg
       </image>
       </image>
       <image number="2"></image>
       <image number="3"></image>
       <image number="4"></image>
       <image number="5"></image>
       <image number="6"></image>
       <Floorplans/>
       </images>
       ```
   
 * If instead I export the xml file I find the code injected into a section <! [
   CDATA [
 *     ```
       <images>
       <![CDATA[
       <image number="1"><image>https://www.dreamvillas.estate/wp-content/uploads/2019/09/11/Historical-Villa-Lake-Como-45.jpg</image></image><image number="2"><image>https://www.dreamvillas.estate/wp-content/uploads/2019/09/11/Historical-Villa-Lake-Como-44.jpg</image></image><image number="3"><image>https://www.dreamvillas.estate/wp-content/uploads/2019/09/11/Historical-Villa-Lake-Como-43.jpg</image></image><image number="4"><image>https://www.dreamvillas.estate/wp-content/uploads/2019/09/11/Historical-Villa-Lake-Como-42.jpg</image></image><image number="5"><image>https://www.dreamvillas.estate/wp-content/uploads/2019/09/11/Historical-Villa-Lake-Como-41.jpg</image></image><image number="6"><image>https://www.dreamvillas.estate/wp-content/uploads/2019/09/11/Historical-Villa-Lake-Como-40.jpg</image></image>
       ]]>
       <Floorplans/>
       </images>
       ```
   
 * How can I solve it?
 * Thanks, Claudio
 *  Thread Starter [K15Lmk98](https://wordpress.org/support/users/k15lmk98/)
 * (@k15lmk98)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12190741)
 * Hi,
    in fact, even a simple function without data
 *     ```
       <images>[cr_get_images()]</images>
       function cr_get_images() {
       	$output = '**LT**image**GT**' . '**LT**/image**GT**';
       return $output;
       }
       ```
   
 * produces a section CDATA in the xml file
 *     ```
       <images>
       <![CDATA[ <image></image> ]]>
       </images>
       ```
   
 * Grazie, Claudio_
 *  Thread Starter [K15Lmk98](https://wordpress.org/support/users/k15lmk98/)
 * (@k15lmk98)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12195331)
 * Hi,
    sorry.
 * I had not seen the option in Advanced Options “Never wrap data in CDATA tags”.
   With this activated your code works well.
 * However, this option may generate a Warning: This may result in an invalid XML
   file.
 * **Question**: there is a way to avoid CDATA tags only in a specific XML node –
   in our example the one that generates the node:
    `<images>[cr_get_images()]</
   images>`
 * Thanks, Claudio_
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12204871)
 * Hi [@k15lmk98](https://wordpress.org/support/users/k15lmk98/)
 * > Question: there is a way to avoid CDATA tags only in a specific XML node – 
   > in our example the one that generates the node
 * We currently don’t have that option, but you can _add_ CDATA tags to any nodes
   that need them with **CDATABEGIN** and **CDATACLOSE**, e.g.:
 * `<Content>CDATABEGIN{Content}CDATACLOSE</Content>`
    -  This reply was modified 6 years, 6 months ago by [WP All Import](https://wordpress.org/support/users/wpallimport/).
 *  Thread Starter [K15Lmk98](https://wordpress.org/support/users/k15lmk98/)
 * (@k15lmk98)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12205582)
 * Thanks for the support.
 * I am not able to know what data will be in the nodes: they are free input data.
 * Are you telling me that I should wrap all the nodes with
    CDATABEGIN {node-example}
   CDATACLOSE?
 * Thanks, Claudio_
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12225224)
 * Hi [@k15lmk98](https://wordpress.org/support/users/k15lmk98/)
 * > Are you telling me that I should wrap all the nodes with CDATABEGIN {node-example}
   > CDATACLOSE?
 * You should do that for any node that you suspect will require CDATA tags: [https://stackoverflow.com/a/2784200](https://stackoverflow.com/a/2784200).
 *  Thread Starter [K15Lmk98](https://wordpress.org/support/users/k15lmk98/)
 * (@k15lmk98)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12226221)
 * Hi,
    I understand, thanks. Claudio_

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

The topic ‘Function that returns data in an array – Wp All Export –’ 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/)

 * 8 replies
 * 2 participants
 * Last reply from: [K15Lmk98](https://wordpress.org/support/users/k15lmk98/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/function-that-returns-data-in-an-array-wp-all-export/#post-12226221)
 * Status: resolved