{"id":5812740,"date":"2023-07-10T21:46:42","date_gmt":"2023-07-10T21:46:42","guid":{"rendered":"https:\/\/www.wpallimport.com\/?post_type=documentation&#038;p=5812740"},"modified":"2025-12-08T17:48:02","modified_gmt":"2025-12-08T17:48:02","slug":"variable-number-of-images-per-post","status":"publish","type":"documentation","link":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/","title":{"rendered":"Variable Number Of Images Per Post"},"content":{"rendered":"\n<p>Sometimes, each record in your XML or CSV file will have a different number of images associated with it. Below are some of the most common ways to handle this scenario with WP All Import. <\/p>\n\n\n\n<p>All settings shown are available in the&nbsp;<strong>Images<\/strong>&nbsp;section of the&nbsp;<strong>Drag &amp; Drop<\/strong>&nbsp;screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"optiona\">Option A: Image URLs Are Stored In A Single Column Or Element, And Separated By A Character<\/h2>\n\n\n\n<p>Simply drag &amp; drop the column or element containing your image URLs or filenames&nbsp;to the appropriate textbox, and change the Separator character if it is different than a comma.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Images-Single-Element-Comma-Separated-scaled.jpg\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" width=\"1024\" height=\"425\" src=\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Images-Single-Element-Comma-Separated-1024x425.jpg\" alt=\"Download Images Single Element Comma Separated\" class=\"wp-image-5812749\" srcset=\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Images-Single-Element-Comma-Separated-1024x425.jpg 1024w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Images-Single-Element-Comma-Separated-300x125.jpg 300w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Images-Single-Element-Comma-Separated-768x319.jpg 768w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Images-Single-Element-Comma-Separated-1536x638.jpg 1536w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Images-Single-Element-Comma-Separated-2048x851.jpg 2048w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Images-Single-Element-Comma-Separated-scaled.jpg 2560w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"optionb\">Option B:&nbsp;Image URLs are Contained In Different CSV Columns or XML Elements<\/h2>\n\n\n\n<p>WP All Import will ignore any blank image URLs, so you can simply specify all possible XPaths that could potentially point to image URLs for certain records. Any that don\u2019t point to image URLs for the current record will be ignored for that record.<\/p>\n\n\n\n<p>1. Go to the&nbsp;record in your XML or CSV file that has the most images in the XML\/CSV tree on the right. You can do this by entering the record number and then clicking anywhere on the XML\/CSV tree:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/changing-records.png\" alt=\"XML Tree View\" class=\"wp-image-412\"\/><\/figure>\n\n\n\n<p>2. Drag &amp; drop all the elements or columns containing image URLs into the image URLs box.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Nine-Images-From-URLs.jpg\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" width=\"1024\" height=\"358\" src=\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Nine-Images-From-URLs-1024x358.jpg\" alt=\"Download Nine Images From URLs\" class=\"wp-image-5812751\" srcset=\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Nine-Images-From-URLs-1024x358.jpg 1024w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Nine-Images-From-URLs-300x105.jpg 300w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Nine-Images-From-URLs-768x269.jpg 768w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Nine-Images-From-URLs-1536x537.jpg 1536w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Nine-Images-From-URLs-2048x716.jpg 2048w, https:\/\/www.wpallimport.com\/wp-content\/uploads\/2023\/07\/Download-Nine-Images-From-URLs.jpg 2184w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Although you can\u2019t see it in the screenshot, in our example, record 179, has 9 different images.<\/p>\n\n\n\n<p>No other records have 9 different images; they have between 1 and 8. WP All Import will simply ignore {image_9[1]} for these other records. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"optionc\">Option C: Use an XPath query or a FOREACH Loop<\/h2>\n\n\n\n<p>If all your image URLs are stored as child elements of some parent element, you can use a FOREACH loop to loop through each child element.<\/p>\n\n\n\n<p>This is only applicable to XML files.<\/p>\n\n\n\n<p>Example XML:<\/p>\n\n\n\n<div class=\"wp-block-wpcodebox-snippet wpcodebox-snippet\" data-language=\"xml\"><pre class=\"line-numbers\"><code class=\"language-xml\">&lt;images&gt;\n    &lt;image src=\u201dimage1.jpg\u201d alt=\u201di am first image\u201d&gt;Featured Image&lt;\/image&gt;\n    &lt;image src=\u201dimage2.jpg\u201d alt=\u201dthis is image2\u2033&gt;Second Image&lt;\/image&gt;\n    &lt;image src=\u201dimage3.jpg\u201d alt=\u201dthis is image3\u2033&gt;Third Image&lt;\/image&gt;\n    &lt;image src=\u201dimage4.jpg\u201d alt=\u201dthis is image4\u2033&gt;Fourth Image&lt;\/image&gt;\n&lt;\/images&gt;<\/code><\/pre><\/div>\n\n\n\n<p>You can use this XPath query to output a comma-delimited list of the image names:<\/p>\n\n\n\n<p><code>{images\/image\/@src}<\/code><\/p>\n\n\n\n<p>Or, if you need to prepend a URL or add something else to the data, you can use a FOREACH loop instead:<\/p>\n\n\n\n<p><code>[FOREACH({images\/image})]<br>http:\/\/www.example.com\/my-folder\/{@src},<br>[ENDFOREACH]<\/code><\/p>\n\n\n\n<p>To learn more about FOREACH loops, please read <a href=\"https:\/\/www.wpallimport.com\/documentation\/foreach-loops\/\" target=\"_blank\" rel=\"noreferrer noopener\">Processing and Grouping Multiple Elements with FOREACH Loops<\/a>.<\/p>\n\n\n\n<div class=\"docs-interstitial\">\n\n    <img decoding=\"async\" src=\"https:\/\/www.wpallimport.com\/wp-content\/plugins\/custom-acf-blocks\/blocks\/docs-interstitial\/img\/octopus-logo.svg\" class=\"docs-interstitial__logo\">    <h3>Import Any CSV, XML, or Excel to WordPress<\/h3>\n    <ul><li>Any theme or plugin<\/li><li>Images &amp; galleries<\/li><li>Custom fields<\/li><li>Categories &amp; tags<\/li><li>Woo, ACF, Meta Box, JetEngine<\/li><\/ul>\n    <div class=\"docs-interstitial__cta\">\n        <a class=\"docs-interstitial__btn\" href=\"#pricing\" target=\"_self\">View Pricing<\/a>\n                    <a class=\"docs-interstitial__text-link\" href=\"https:\/\/www.wpallimport.com\/import-wordpress-csv-xml-excel\/\" target=\"_self\">\n                Product Tour\n                <div class=\"docs-interstitial__text-link-arrow\">\n                    <svg width=\"13\" height=\"11\" viewBox=\"0 0 13 11\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M8 1.5L12 5.5L8 9.5\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><\/path>\n                    <path d=\"M11.5 5.5H1\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\"><\/path>\n                    <\/svg>\n                <\/div>\n            <\/a>\n            <\/div>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Related Docs<\/h2>\n\n\n\n\n\n<p>Provides instructions on how to import images from URLs.<\/p>\n\n\n\n\n\n<p>Learn how to import images from the Media Library.<\/p>\n\n\n\n\n\n<p>Shows you how to import images uploaded to \/wp-content\/uploads\/wpallimport\/files\/.<\/p>\n\n\n\n\n\n<p>Explains the different image options available.<\/p>\n\n\n\n\n\n<p>Elaborates on importing metadata to your images.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Import all of your images for each record from your CSV or XML file even if the number of images per record in your file changes.<\/p>\n","protected":false},"author":96198,"featured_media":2990165,"parent":2991548,"menu_order":3,"template":"","tags":[138],"content_author":[213],"search_tags":[],"class_list":["post-5812740","documentation","type-documentation","status-publish","has-post-thumbnail","hentry","tag-w-article","content_author-editorial-staff"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Import Variable Numbers of Images Per Post - WP All Import<\/title>\n<meta name=\"description\" content=\"Import all of your images for each record from your CSV or XML file even if the number of images per record in your file changes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Import Variable Numbers of Images Per Post - WP All Import\" \/>\n<meta property=\"og:description\" content=\"Import all of your images for each record from your CSV or XML file even if the number of images per record in your file changes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/\" \/>\n<meta property=\"og:site_name\" content=\"WP All Import\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/groups\/wpallimport\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-08T17:48:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/separated-by.png\" \/>\n\t<meta property=\"og:image:width\" content=\"805\" \/>\n\t<meta property=\"og:image:height\" content=\"161\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data2\" content=\"Editorial Staff\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/\",\"url\":\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/\",\"name\":\"Import Variable Numbers of Images Per Post - WP All Import\",\"isPartOf\":{\"@id\":\"https:\/\/www.wpallimport.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/separated-by.png\",\"datePublished\":\"2023-07-10T21:46:42+00:00\",\"dateModified\":\"2025-12-08T17:48:02+00:00\",\"description\":\"Import all of your images for each record from your CSV or XML file even if the number of images per record in your file changes.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/#primaryimage\",\"url\":\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/separated-by.png\",\"contentUrl\":\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/separated-by.png\",\"width\":805,\"height\":161},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wpallimport.com\/#website\",\"url\":\"https:\/\/www.wpallimport.com\/\",\"name\":\"WP All Import\",\"description\":\"Import XML &amp; CSV to WordPress\",\"publisher\":{\"@id\":\"https:\/\/www.wpallimport.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wpallimport.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.wpallimport.com\/#organization\",\"name\":\"WP All Import\",\"url\":\"https:\/\/www.wpallimport.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wpallimport.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/logo-v5-no-text.svg\",\"contentUrl\":\"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/logo-v5-no-text.svg\",\"width\":199,\"height\":37,\"caption\":\"WP All Import\"},\"image\":{\"@id\":\"https:\/\/www.wpallimport.com\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Import Variable Numbers of Images Per Post - WP All Import","description":"Import all of your images for each record from your CSV or XML file even if the number of images per record in your file changes.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/","og_locale":"en_US","og_type":"article","og_title":"Import Variable Numbers of Images Per Post - WP All Import","og_description":"Import all of your images for each record from your CSV or XML file even if the number of images per record in your file changes.","og_url":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/","og_site_name":"WP All Import","article_author":"https:\/\/www.facebook.com\/groups\/wpallimport","article_modified_time":"2025-12-08T17:48:02+00:00","og_image":[{"width":805,"height":161,"url":"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/separated-by.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes","Written by":"Editorial Staff"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/","url":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/","name":"Import Variable Numbers of Images Per Post - WP All Import","isPartOf":{"@id":"https:\/\/www.wpallimport.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/#primaryimage"},"image":{"@id":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/separated-by.png","datePublished":"2023-07-10T21:46:42+00:00","dateModified":"2025-12-08T17:48:02+00:00","description":"Import all of your images for each record from your CSV or XML file even if the number of images per record in your file changes.","breadcrumb":{"@id":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wpallimport.com\/documentation\/variable-number-of-images-per-post\/#primaryimage","url":"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/separated-by.png","contentUrl":"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/separated-by.png","width":805,"height":161},{"@type":"WebSite","@id":"https:\/\/www.wpallimport.com\/#website","url":"https:\/\/www.wpallimport.com\/","name":"WP All Import","description":"Import XML &amp; CSV to WordPress","publisher":{"@id":"https:\/\/www.wpallimport.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wpallimport.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.wpallimport.com\/#organization","name":"WP All Import","url":"https:\/\/www.wpallimport.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wpallimport.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/logo-v5-no-text.svg","contentUrl":"https:\/\/www.wpallimport.com\/wp-content\/uploads\/2020\/02\/logo-v5-no-text.svg","width":199,"height":37,"caption":"WP All Import"},"image":{"@id":"https:\/\/www.wpallimport.com\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/documentation\/5812740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/types\/documentation"}],"author":[{"embeddable":true,"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/users\/96198"}],"version-history":[{"count":0,"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/documentation\/5812740\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/documentation\/2991548"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/media\/2990165"}],"wp:attachment":[{"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/media?parent=5812740"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/tags?post=5812740"},{"taxonomy":"content_author","embeddable":true,"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/content_author?post=5812740"},{"taxonomy":"search_tags","embeddable":true,"href":"https:\/\/www.wpallimport.com\/wp-json\/wp\/v2\/search_tags?post=5812740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}