Custom post edit with button to save post and start creating new

I have custom post edit screen with custom metaboxes and wanted the last metabox to Save this post and start creating a new one.

It's easy to redirect user to new post creation page with url like post-new.php?post_type=customposttype but what url should I call with javascript before this to make the post saved?

Thanks

    add_meta_box(addanotheritem, 'Add another', 'addanother_metabox', 'custompost', 'side', 'high'); 

        
    function addanother_metabox() {  
    
    ?  
        script type=text/javascript  
         function saveAndGo() {  
            jQuery('button.editor-post-publish-button__button').click();  
            window.location='./post-new.php?post_type=custompost';  
            return false;  
         }  
        /script  
        button onclick='javascript:saveAndGo();'save  add another/button  
        ?php  
    }  

Topic autosave Wordpress

Category Web


I know this is kinda stupid solution, but 2s timeout is acceptable solution

 add_meta_box("addanotheritem", 'Add another', 'addanother_metabox', 'custompost', 'side', 'high'); 

        
    function addanother_metabox() {  
    
    ?>  
        <script type="text/javascript">  
         function saveAndGo() {  
            jQuery('button.editor-post-publish-button__button').click();  
            setTimeout(function() {
                        window.location='./post-new.php?post_type=custompost';
                    }, 2000);   
            return false;  
         }  
        </script>  
        <button onclick='javascript:saveAndGo();'>save & add another</button>  
        <?php  
    }  

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.