1

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?

1
  • How do you insert the images in the content? Usually this shouldn't refresh the page at all. Also: post metadata is currently not auto-saved to revisions, see core.trac.wordpress.org/ticket/20299
    – swissspidy
    Commented Aug 6, 2013 at 9:11

1 Answer 1

0

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.

Your Answer

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

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