How to trigger the WP post page to save a post automagically
November 9, 2011 – 8:22 pm |There may be a time as a plugin developer when you wrote a plugin that effects the post-editing or page-editing interface for WordPress. In this case, you may also need to somehow trigger the content to auto save, like WordPress will do automatically from time to time.
The best and easiest way to do this without a page reload, is to call the “autosave()” function in JavaScript.
For example, let’s say you somehow added a custom field to the page that is controlled by a new input field instead of with the custom fields form.
You could have the code look something like this when it is rendered:
-
-
<input type="text" name="my_custom_field" id="my_custom_field" value="<?php echo $my_custom_field;?>">
Then, in your additional JavaScript you could do this:
-
-
jQuery('#my_custom_field').change(function(){
-
-
autosave(); //saves the whole post interface
-
-
});
Of course, I am cutting A LOT of corners here. The point is not to show you have to add a custom field input to your post page, but more so to show you how to trigger a save on your posts or page edit pages. Good Luck!

