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.

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 them from the menu and will also remove page from the site as well.

I found this statement

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.

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

A faster solution is:

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

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

share|improve this answer
Yes, a faster and simpler solution. Plus then it will only worry about writing the update to status and not bother having to re-update or ignore all the other data retrieved in the current post – Kirby Nov 10 at 19:37

Your Answer


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