Multiple media upload custom post
-
Hello!
I am making a custom post type with a custom meta box. In this meta box I want to add a function to select multiple images. So I have made a function that get’s all the ID’s from the selected images and storing them in the postmeta table in the DB. The ID’s are saved as a string and the ID’s are separated by a ‘,’.
However here is my problem, I want to make it possible that when you close the media uploader a preview of all the images you have chosen would appear in the meta box. Here is my code:
imageUploader.on( 'close', function() { //var attachment = imageUploader.state().get('selection').first().toJSON(); var attachment = imageUploader.state().get('selection'); var ids = attachment.map( function (attachment) { return attachment.id; console.log(ids); }); jQuery.each(ids,function(i) { if (i > 0) jQuery('#image-tag').prepend( function(attachment) { var output = ''; output += '<img src="'+attachment.url+'" width="150" height="150" />'; return output; }); }); hidden.setAttribute( 'value', ids.join() ); console.log(attachment); });it works, but for one reason I cant get the image URL. I can’t get the image ID, title or thumbnail url either. In the inspector console I get a message that says “undefined”.
Hope someone could help me out 😄
The topic ‘Multiple media upload custom post’ is closed to new replies.