Update status of all posts in a category

I am sure there’s an easier way to accomplish this, but this how I would’ve done.

  1. Query all posts with category X and status X
  2. Update query results with status Y.

    $target_category = 'news';
    $change_status_from = 'draft';
    $change_status_to = 'publish';
    $update_query = new WP_Query(array('post_status'=>$change_status_from, 'category_name'=>$target_category, 'posts_per_page'=>-1));
    
    if($update_query->have_posts()){
    
        while($update_query->have_posts()){
    
            $update_query->the_post();
            wp_update_post(array('ID'=>$post->ID, 'post_status'=>$change_status_to));
    
        }
    
    }
    

You can place this code inside a page template, or in functions.php. It’s likely that you only need to run it every now and then. So I would create a template for it. Add it to the template and then assign that template to a specific page that’s maybe marked as private or draft.