I am using the below code to allow a logged in user to set delete their own posts from the front end. Is there a way to do the same thing but setting the post to ‘draft’ rather than deleting it completely?
<?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 } ?>
use this function
wp_update_post()
, you can test with this example:First create a form were you want to users select if the post are going to be a draft
Then create a function to save the new state put this in function.php:
Then add this function below the form you create.
And test. Read this to know more about update post status