1

In my plugin I need a media uploader exactly like the one you see when you select a post's featured image.

I managed to do almost everything with this code:

media_uploader = window.wp.media({
    frame: 'select',
    title: 'Carica le foto',
    multiple: true,
    library: {
        type: 'image',
        search: null,
        uploadedTo: postID
    },
    button: {
        text: 'Imposta come principale'
    }
});

The problem is that I can't sort the uploaded images. If I click and drag the images in the media uploader, the images are stuck.

I can see that in my uploader there is the class ui-sortable-disabled wich is absent in the "default" one (see images below). I searched in the documentation but I didn't find anything useful about this topic.

Wordpress "default" uploader

My custom uploader

3
  • the sortable functionality is usually used for galleries as a separate additional step or in the pane in the bottom
    – Tom J Nowell
    Commented Jan 24, 2022 at 14:34
  • That's exactly why I need to sort the images. I show all of them as a gallery after and I want the user to be able to sort them.
    – Pacicio
    Commented Jan 28, 2022 at 8:31
  • could you not reuse the gallery uploader? What you're trying to do and what the gallery does aren't the same thing, the gallery have a 2 step selection stage followed by a sorting/caption stage. Even then, nothing prevents you sorting the selected items in your page via JS once the modal dialog has been closed
    – Tom J Nowell
    Commented Jan 28, 2022 at 15:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.