Wait!

Lifetime licenses are only available for a short time, don't miss out!

Any File Type

No need to reorganize your data, just upload your file to WP All Import and it'll sort it out.

Complete Customization

Granular control over every single piece of data. Think your import is too complicated? Think again.

Import Huge Datasets

It doesn't matter how big your site is or how much data you need to import, WP All Import can handle it. 

Multilingual Imports

Importing data to multilingual sites has never been easier, with support from the WPML team.

Scheduled Imports

Run imports automatically on a schedule. Subscribe to our point and click scheduling service, or set up cron jobs.

Developer Friendly

Write and test PHP right inside WP All Import when setting up your import, with tons of snippets to get you started.
@glitzformals
"This plugin is a game changer for my situation. I’m stunned at how fast and effortless the import process is."
@adatfalo
"I have never experienced such a quick and helpful support experience with any plugin, and by the way, the knowledge of the support colleagues is professional!"
@jessedw44
"Even if you just use this plugin once, it will save you time. If you work on several sites its invaluable. Constantly developed, and continuously supported. Great job."
90-Day Guarantee
Not 100% happy? Let us know and we’ll promptly send you a refund.
Free Updates For Life
Pay once for unlimited installs, even client sites. No renewal fees.
Fast, World Class Support
Over 9 years experience with WordPress imports and exports.
Now is your last chance to buy a lifetime license before we switch to annual pricing. Existing licenses will be unaffected.
Read More

Processing and Grouping Multiple Elements with FOREACH Loops

WP All Import supports a FOREACH syntax that makes it easy to make adjustments to multiple elements from your file at the same time. This is useful when building custom HTML in the Content section, or when preparing other data from your file for fields that require a specific format.

Here's an example showing how to implement a FOREACH loop in WP All Import.

Here's an example XML file that contains some image information – It is assumed the default (/element) was chosen as the XPath in Step 2.

<root>
 <elements>
  <element>
   <id>1</id>
   <images>
    <img url='1-1.jpg'>My Caption</img>
    <img url='1-2.jpg'>Another Caption</img>
    <img url='1-3.jpg'>We will use these for alt text</img>
    <img url='1-4.jpg'>More text</img>
   </images>
  </element>
 </elements>
</root>

Here’s an example import template where FOREACH is used to loop through each img element in the above XML.

[FOREACH({images/img})]
<img src="{@url}" alt="{.}" />
[ENDFOREACH]

Passing {images/img} to the FOREACH means we will loop through each element matching that XPath. To get this XPath, just drag one of the matching elements from the XML tree on the right to the post content box. You’ll get something like {images/img[1]}. Just remove the [1] and you’re good to go.

Inside the FOREACH loop, the XPath is relative. You can’t access “higher-level” elements inside the FOREACH loop. For example, you wouldn't be able to access the 'id' element from within the FOREACH loop.

{@url} will return the url attribute of the element you are looping through - '1-1.jpg', '1-2.jpg', etc.

{.} will return the value of the element you are looping through – in this case, each img - 'My Caption', 'Another Caption', etc.

{element_name} will return the value of the element_name child element of the element you are looping through.


 

 

Related

Inline PHP

IF Statements

Lifetime support. Lifetime updates. Pay once.

Packages
Standalone
Import
Pro Package
$249
one-time
  • Import Pro
Import Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
  • Types
  • Export Pro
Export Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
Add to Cart
90 Day Money Back Guarantee
Import + Export Pro Package
$299
one-time
  • Import Pro
Import Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
  • Types
  • Export Pro
Export Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
Add to Cart
90 Day Money Back Guarantee
WooCommerce Import Package
$149
one-time
  • Import Pro
Import Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
  • Types
  • Export Pro
Export Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
Add to Cart
90 Day Money Back Guarantee
Import Standalone
$99
one-time
  • Import Pro
Import Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
  • Types
  • Export Pro
Export Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
Add to Cart
90 Day Money Back Guarantee
Import + Export Standalone
$169
one-time
  • Import Pro
Import Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
  • Types
  • Export Pro
Export Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
Add to Cart
90 Day Money Back Guarantee
Export Standalone
$99
one-time
  • Import Pro
Import Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
  • Types
  • Export Pro
Export Add-Ons
  • WooCo
  • ACF
  • Gravity Forms
  • Users
Add to Cart
90 Day Money Back Guarantee
cross