Support

Account

Home Forums Front-end Issues Change Post Status on Edit Reply To: Change Post Status on Edit

  • Looking back at the code, I think it may have something to do with the call to update post, not sure why that’s in there, either that of the insert post. Looking at it, since we’re updating the post the the insert needs to be removed and an change is needed to the update.

    try this.

    
    <?php 
    
      function my_pre_save_post($post_id) {
      
        // check for numerical post_id and check post_type
        if (!is_numeric($post_id) || get_post_type($post_id) != 'post') {
          return $post_id;
        }
    
        // update status to draft
        $post = array(
          'ID' => $post_id,
          'post_status'  => 'draft' ,
        );  
    
        // update the post
        wp_update_post($post);
        
        return $post_id;
      }
      
      add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
      
    ?>