Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a front-end posting and dashboard system for my users to add and edit their own posts. In the dashboard area, I have a list of their posts and the following options for each post: View | Edit | Publish/Un-Publish | Delete

I have all of these links working except for the "un-publish" part. I can get a post to publish if it's currently in draft, but once it publishes I can't figure out how to "unpublish" it from the front end, which is a function I'd like my users to have.

For reference, I am using code from this thread to do the Publish part: Front-End Post Submission

I've tried adapting it, but have not succeeded.

I also need similar functionality on the New Post form where I'd like to display a "Save Post" button along side the "Publish" button so a user can save the post a draft so as to not risk losing their work while creating the post.

Thanks for reading, and hopefully someone can help!

share|improve this question

1 Answer 1

You can use wp_update_post() to change the status of a post.

global $current_user;
get_currentuserinfo();

$post_id = $_GET['post_id'];
$the_post = get_post( $post_id );

if ( $the_post->post_author == $current_user->ID && $the_post ) {
    $the_post->post_status = 'draft';
    wp_update_post( $the_post );    
}

Use wp_insert_post() with post_status => 'draft' to save a post.

share|improve this answer
    
Thank you, this was helpful! I also don't completely understand nonce yet so there was also an error going on there. Thanks for your help. –  Eckstein Nov 10 '12 at 6:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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