将Wordpress post状态设置为';草案';从前端类似于get_delete_post_链接

将Wordpress post状态设置为';草案';从前端类似于get_delete_post_链接,wordpress,post,frontend,status,Wordpress,Post,Frontend,Status,我使用下面的代码允许登录用户设置从前端删除自己的帖子。有没有办法做同样的事情,但将帖子设置为“草稿”而不是完全删除 <?php if ($post->post_author == $current_user->ID) { ?> <p><a onclick="return confirm('Are you SURE you want to delete this?')" href="<?php echo get_delete_post_link

我使用下面的代码允许登录用户设置从前端删除自己的帖子。有没有办法做同样的事情,但将帖子设置为“草稿”而不是完全删除

<?php if ($post->post_author == $current_user->ID) { ?>
   <p><a onclick="return confirm('Are you SURE you want to delete this?')" href="<?php echo get_delete_post_link( $post->ID ) ?>">Delete post</a></p>
<?php } ?>


使用此函数
wp\u update\u post()
,您可以使用以下示例进行测试:

首先创建一个表单,您希望用户选择该帖子是否为草稿

<form action="" method="POST" >
    <input type="checkbox" value="ok" name="draft">
    <input type="submit" value="Ok">
</form>
然后在创建的表单下方添加此函数

toDraft($post->ID);

和测试。要了解有关更新帖子状态的更多信息,请参见

,谢谢。工作完美。如何将警报框添加到提交中,然后重定向到另一个页面?您需要javascript来执行警报框,使用jquery
submit()
函数,并使用
window.location
重定向。
toDraft($post->ID);