I have about 2300+ post in my blog is it possible to change status from publish to draft at a time?
add_action('publish_post', 'check_publish_post', 10, 2);
function check_publish_post ($post_id, $post) {
$query = array(
'ID' => $post_id,
'post_status' => 'draft',
);
wp_update_post( $query, true );
}
Yes, it’s possible to loop all publish posts and change their post status to draft.
add_action('admin_init','wpse_244394');
function wpse_244394(){
$args = array('post_type'=> 'post',
'post_status' => 'publish',
'posts_per_page'=>-1
);
$published_posts = get_posts($args);
foreach($published_posts as $post_to_draft){
$query = array(
'ID' => $post_to_draft->ID,
'post_status' => 'draft',
);
wp_update_post( $query, true );
}
}