Update current WP post every 3 minutes
I wish to auto update/publish the changes of a post I am editing every 3 minutes. Any idea how can I achieve that?
I wish to auto update/publish the changes of a post I am editing every 3 minutes. Any idea how can I achieve that?
Classic Editor:
autosave.js file
setInterval(function () {document.getElementById("publish").click()}, 300000);
php function
// Load js file on specific post type in class editor
function load_js_file_classic_editor( $hook ) {
global $post;
if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
if ( 'post' === $post->post_type ) {
wp_enqueue_script( 'myautosave', get_stylesheet_directory_uri().'/includes/js/autosave.js' );
}
}
}
add_action( 'admin_enqueue_scripts', 'load_js_file_classic_editor', 10, 1 );
Gutenberg
setInterval(function() {
wp.data.dispatch( 'core/editor' ).savePost();
}, 60 * 1000); // 60 * 1000 milsec
Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.