admin管理员组文章数量:1305022
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
}
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
}
Share
Improve this question
edited Jan 28, 2021 at 9:24
mik256
asked Jan 26, 2021 at 22:13
mik256mik256
11 bronze badge
12
- perhaps bind a click event to the editor save button? – Q Studio Commented Jan 26, 2021 at 22:50
- that would be great, how this can be done? – mik256 Commented Jan 27, 2021 at 7:51
- 1 Amazing. Thank you! – mik256 Commented Jan 27, 2021 at 22:19
- 1 sorry, I have already updated the question – mik256 Commented Jan 28, 2021 at 9:03
- 1 need to study about promises, but I got the solution, I used "stupid" timeout and it works – mik256 Commented Jan 28, 2021 at 9:27
1 Answer
Reset to default 0I 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
}
本文标签: autosaveCustom post edit with button to save post and start creating new
版权声明:本文标题:autosave - Custom post edit with button to save post and start creating new 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741797451a2398019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论