Created
February 5, 2019 17:06
-
-
Save digamber89/ba20be8825b1fb075d816206cb04795d to your computer and use it in GitHub Desktop.
Multiple Upload WordPress Media
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function enqueue_media_uploader() | |
{ | |
wp_enqueue_media(); | |
} | |
add_action("admin_enqueue_scripts", "enqueue_media_uploader"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var media_uploader = null; | |
function open_media_uploader_multiple_images() | |
{ | |
media_uploader = wp.media({ | |
frame: "post", | |
state: "insert", | |
multiple: true | |
}); | |
media_uploader.on("insert", function(){ | |
var length = media_uploader.state().get("selection").length; | |
var images = media_uploader.state().get("selection").models | |
for(var iii = 0; iii < length; iii++) | |
{ | |
var image_url = images[iii].changed.url; | |
var image_caption = images[iii].changed.caption; | |
var image_title = images[iii].changed.title; | |
} | |
}); | |
media_uploader.open(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment