WP 3.5 media uploader API set selected item

I found the solution from here:

https://stackoverflow.com/questions/13936080/pre-select-images-when-opening-wordpress-3-5-media-manager

And it works. Here’s my modification and this is using a single-image select media frame:

frame.on('open', function(){
    var selection = frame.state().get('selection');
    var selected = $('#image-id').val(); // the id of the image
    if (selected) {
        selection.add(wp.media.attachment(selected));
    }
});

Leave a Comment