0

I would like to import an image to an pods.io custom image field. I tried

$api = pods_api( 'boek' );
$data = array(
    0 => array(
            'post_title' => 'slug',
            'name' => 'test1',
            'isbn13' => '9780000000001',
            'producttype' => 'Paperback',
            'nur' => 200,
            'omslag' => pods_attachment_import( 'http://barcelonainfo.nl/wp-content/uploads/2012/08/Boek_open.jpg' )
    ),
);

// Run the import
$api->import( $data );

omslag is a file/image/video field. The image is imported but not attached to the POD in the omslag field.

Mike
  • 91
  • 2
  • 8

1 Answers1

1

You need to set 'omslag' to the ID of the attachment. In this case it looks like the image is already attached since its in your uploads folder, so you should find its ID and set that ID as the value for 'omslag'.

In general, when using the pods_attachment_import() it's best to use it and then pass the return value from the function, which is attachment ID to the import array.

JPollock
  • 3,218
  • 4
  • 26
  • 36
  • Hi @Jpollock, I thought it would work like that but it isn't. The image used in the example is from a random internet site. When I run the script the image is added to my media library but not attached to my pods (boek). When I do the same with a single pod and use add() it works as expected. Do you have any idea? – Mike Jun 23 '14 at 13:21
  • I'm not positive, but I think it may be because your array is multi-dimensional. I've always done this as `$data = array( 'post_title' => 'slug',` etc... If you need to do more than one item at once, use a foreach loop. – JPollock Jun 24 '14 at 15:18