1

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 --> <?php if( 'POST' == $_SERVER['REQUEST_METHOD'] ) { 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"> <p> <?php _e( 'No Lists found.', 'lists' ); ?> </p> </div> <?php endif; ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <h1 class="entry-title center">Your Lists</h1> </header> <div class="entry-content"> <div class="table style1"> <div class="tr"> <div class="td style2"> <h2>Date And Time</h2> </div> <div class="td"> <h2>Delete</h2> </div> </div> <?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" /> </form> <?php echo '</div></div>'; ?> <?php endwhile; ?> <?php wp_reset_query(); ?> <div class="tr"> <div class="td style2"> <h2>Date And Time</h2> </div> <div class="td"> <h2>Delete</h2> </div> </div> </div> </div><!-- .entry-content --> </article><!-- #post --> <!-- /buyer-home.php --> 

1 Answer 1

0

Simply replace

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

with

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

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

3
  • 1
    My code works just fine, im not sure what logic has to do with it. however yours gives errors Commented 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. Commented 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. Commented Apr 17, 2013 at 11:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.