Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to figure out how to write the code that will allow me to do the following with pages of a WordPress blog?

"To change a post status, you get the post, change its status field, then call wp_update_post with the new post object"

The closest existing plugin is - Except that this plugin uses wp-list-pages and it only hides them and does not actually move them from publish to draft. I need to have something where I specify which page ID's I want to list (about 15 total) and then give the user the ability to select which ones will be published or which ones will be a draft - this will remove from menu and will also remove page from site as well...

share|improve this question

2 Answers 2

Here is a function that changes post status

$post_id - The ID of the post you'd like to change.
$status -  The post status publish|pending|draft|private|static|object|attachment|inherit|future|trash.
function change_post_status($post_id,$status){
    $current_post = get_post( $post_id, 'ARRAY_A' );
    $current_post['post_status'] = $status;

simple call the function and pass the post id and the new status you want it to have for example:

share|improve this answer
Thank you very much!Q –  user4064 Mar 19 '11 at 22:49
How would I be able to add the ability make the status an option to select..? I want to be able to toggle between publish and draft only and then update the post with the selected option... –  user4064 Mar 19 '11 at 22:50
You do know that you have a select dropdown just for that in the edit screen? –  Bainternet Mar 20 '11 at 0:15
ha ha.. yes.. but I am trying to build a custom admin options page that will avoid that page.. I would like to have a list of specific available pages and give the admin user the ability to just toggle between having it be published.. or as a draft (unpublished) - I know it can be done, but I am struggling with the code to do it. –  user4064 Mar 20 '11 at 1:53
update your question with the coed you have and i'll get a better view of where i can help. –  Bainternet Mar 20 '11 at 1:59

I think a faster solution would be:

$post = array( 'ID' => $post_id, 'post_status' => $status );

This way you don't have to get the post.

share|improve this answer

Your Answer


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