1

How to set post_id to 0 when you upload image via Add media button which will make a requtest to async-upload.php Instead of actual post_id?

Thank you.

  • 2
    Can you give some context as to why to do it? Maybe there is different solution then the one you think of. – Mark Kaplun Dec 16 '15 at 4:48
  • Hi Mark, I'm working on a plugin that allows registered users to write a post from front-end (and uploading images). The problem I have is that when people upload image by Add Media button, it will get post_parent ID as the parent page that contains my plugins shortcode. I'm thinking setting this to 0 when people upload images and update it to newly created post when they click submit button. – Ohsik Dec 16 '15 at 18:07
1

Finally found an answer for this and checked it worked on my situation. How to upload image without post ID using the new media uploader?

// Set post_id to 0 when Add Media button clicked
jQuery('#insert-media-button').on('click', function( event ){
    event.preventDefault();
    wp.media.model.settings.post.id = 0;
});

This will set all the images uploaded via Add media button to 0 which will show up as (Unattached) in backend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.