I am using the code in a page below to let users delete their posts from the front in. I have wp-admin totally blocked off to site users.

What i want to do is when they click the delete button the post actually goes into draft or pending mode so there is still a record of the post but the front end cant view it.

<!-- buyer-home.php -->
 set_query_var( 'postid1', $_POST['postid'] );
 wp_delete_post( get_query_var( 'postid1'), true ); }; ?>
 <?php query_posts( array( 'author' => $current_user->ID,'post_status' =>  'publish' , 'post_type' => array(    'user_lists' )  ) ); ?>
   <?php if ( !have_posts() ): ?>
  <div class="info" id="message">
   <?php _e( 'No Lists found.', 'lists' ); ?>
<?php endif; ?>
 <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title center">Your Lists</h1>
 <div class="entry-content">
<div class="table style1">
  <div class="tr">
    <div class="td style2">
      <h2>Date And Time</h2>
    <div class="td">
     <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
     <?php echo '<div class="tr"><div class="td style2">';
    echo '<a href="'; the_permalink(); echo '">'; the_time('F j, Y'); ?> at
      <?php the_time('g:i a'); echo '</a>';
         echo '</div><div class="td">'; ?>
    <?php  change_post_status( the_ID, 'private'); ?>
     <form class="delete-list" action="" method="post">
      <input type="hidden" name="postid" value="<?php the_ID(); ?>" />
      <input class="more-button" type="submit"  value="Delete" />
    <?php  echo '</div></div>'; ?>
     <?php endwhile; ?>
    <?php wp_reset_query(); ?>
    <div class="tr">
        <div class="td style2">
      <h2>Date And Time</h2>
    <div class="td">
    </div><!-- .entry-content --> 
    </article><!-- #post --> 
     <!-- /buyer-home.php --> 

1 Answer 1


Simply replace

wp_delete_post( get_query_var( 'postid1'), true );


wp_update_post( array( 'ID' => get_query_var( 'postid1' ), 'post_status' => 'draft' ) );

That is assuming that the rest of your logic does already work.

  • 1
    My code works just fine, im not sure what logic has to do with it. however yours gives errors Apr 17, 2013 at 10:53
  • When using "logic" the way I meant it, it's interchangeable with "code". Also, it was not my intention to say that your code isn't okay, I simply have not read through all of it. I was saying that the above will work, provided that the rest of your code does. And that still holds - if you are getting errors, it is not from the above one-liner. Apr 17, 2013 at 11:08
  • no it wasnt, i was copying over the closing }; when pasting your code. not your fault sorry. about to get to testing it. Apr 17, 2013 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.