WP All Import Plugin - Image Foreach loop

2.3k views Asked by At

I'm a WordPress beginner so please bear with me. I'm currently using WP All Import to import my data, and there are a few images are stored as child elements of some parent element.

Following are the screen shot of the XML which exported from phpMyAdmin. The structure is different from what I see from WP All Import youtube tutorial. I'm not sure whether this is correct but the data can imported successfully.

enter image description here enter image description here

From the screen shot (please take note on red boxes), I have same information with different id and images. My question is can I use the Foreach loop for my case? And how to write the Foreach loop based on my case?

This is the code I took from WP All Import website. But I cannot follow exactly same as my XML has different structure.

Example XML:

<images>
<image src=”image1.jpg” alt=”i am first image”>Featured Image</image>
<image src=”image2.jpg” alt=”this is image2″>Second Image</image>
<image src=”image3.jpg” alt=”this is image3″>Third Image</image>
<image src=”image4.jpg” alt=”this is image4″>Fourth Image</image>
</images>

Use the following FOREACH loop:

[FOREACH({images/image})]
http://www.example.com/my-folder/{@src},
[ENDFOREACH]
1

There are 1 answers

0
Evelyn On BEST ANSWER

I solved it by using SQL GROUP CONCAT to combine all the images into same id.

SELECT *, GROUP_CONCAT(DISTINCT concat('<img><url>',filename,'</url></img>') SEPARATOR '\n')
FROM album_pictures 
GROUP BY album_id

So this is the result:

enter image description here

The I used FOREACH loop to read all the images.

[FOREACH({column[22]/img})]
http://www.example.com/my-folder/{url[1]}
[ENDFOREACH]