How to upload image without post ID using the new media uploader?

In the past when using thickbox to upload images, an image could be uploaded without having the post ID ‘attached’ to it by simply using the code below :

jQuery('.upload_slider_button').click(function() {
     tb_show('', 'media-upload.php?post_id=&type=image&TB_iframe=true&referer=matrix-settings');
     return false;
});

However, how can I achieve the same thing using the new Media Uploader which was introduced since WP3.5? I have spent the whole day searching in the internet but there isn’t much resources available on this new media uploader. Most of it are focused on utilizing it in theme options / plugins.

Read More

Or perhaps there are other ways of uploading an image without having the post ID ‘attached’ to it and yet not using any plugins?

Thanks a lot for helping.

Related posts

1 comment

  1. Well, I have finally figured it out. Using Mike’s example here, I just need to put this code wp.media.model.settings.post.id = 0 at this place :

    event.preventDefault();
    
        wp.media.model.settings.post.id = 0;
    
        // If the media frame already exists, reopen it.
        if ( file_frame ) {
            file_frame.open();
            return;
        }
    

    This will cause the image to be uploaded as ‘Unattached’. Hope this helps someone facing this problem in the future.

Comments are closed.