• Resolved khvoroffski

    (@khvoroffski)


    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

    (@wpallimport)

    Hi @khvoroffski

    You can use a PHP function to do that: 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.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @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

    (@khvoroffski)

    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.
    Plugin Author WP All Import

    (@wpallimport)

    Hi @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.

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

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