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 callwp_update_post
with the new post object
The closest existing plugin is http://wordpress.org/extend/plugins/wp-hide-pages/ except that this plugin uses wp-list-pages
. And, it only hides them and does not actually move them from Publish to Draft.
A faster solution is:
This way you don’t have to get the post.
Here is a function that changes post status
simple call the function and pass the post id and the new status you want it to have for example: