Jump to content

import images with custom fields


froot
 Share

Recommended Posts

I'm using custom fields for images (as mentioned here: processwire.com/blog/posts/pw-3.0.142) for a specific images-field, the images of which need to have an HTML-caption. It works fine so far. Now I'm trying to import pages that use this field. I first exported some pages of that kind to see what the spreadsheet would look like. It seems to not separate the captions for each images but instead put all images in one cell and all captions in another.

How could I go about importing these pages and assign the captions to the images accordingly?

Link to comment
Share on other sites

I'd suggest writing a script (https://processwire.com/docs/front-end/include/) to load the data from a CSV or similar, with the data including a URL or path to each image.

The structure of the data file could be whatever is easiest to handle in the script. It doesn't sound as if what you exported is all that helpful as an example.

A couple of posts that might be useful:

https://processwire.com/talk/topic/1153-adding-images-to-a-page-via-the-api/

https://processwire.com/talk/topic/21183-adding-image-to-page-via-api-page-images-add-solved/

 Note that adding data to the custom fields is straightforward, and just like adding to the image description. For example, if you have a custom field named "caption":

$addedImage->caption = "Text for the caption.";

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...