Found 2 other questions similar (almost the same?) as mine:
And found the solution in one of the comments in the latter. It links to a ticket and the last post has the solution to it:
var customMedia = wp.media({
state: 'customState',
states: [
new wp.media.controller.Library({
id: 'customState',
title: 'Library',
library: wp.media.query({
type: 'image',
category: 'icon' // adding a filter to ajax_query_attachments_args
}),
multiple: false,
date: false,
})
]
});
// This will add the item uploaded to the list of attachments in the moodal
customMedia.states.get('library').get('library').observe( wp.Uploader.queue );
This won’t fix the issue when opening the modal again. It doesn’t show the images that were just added.