I have a custom post type with two custom meta boxes.
The first meta box is a gallery that allows me to upload some images.
The second meta box is a drop-down with some options.
I selected an option from second meta box.
Then, inside the first meta box, I have a button to open WP Media Uploader. After I have uploaded some images and clicked the ‘Insert selected Images’. My browser will auto refresh because of the gallery(It needs to show thumbnail of those images).
My problem is when the browser is refreshed, my second custom meta box data will be gone.
I need to trigger the save_as_draft function for the WP Media Uploader when I click the ‘Insert Selected Images’. Any ideas?
Is it the page refresh that’s causing the issue, or do you simply want to save the post before it refreshes? If the later then It’s simple enough with js to check if a condition has changed (ie a button click) in the dom and then:
jQuery("input#save-post").click().prop('disabled', true);
This will of course trigger a full page refresh. You may have to hijack the ‘Insert selected Images’ button’s default behavior altogether to negotiate a possible race condition with the page refresh automatically.