Support

Account

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

  • This filter can also be used for other purposes, for example changing the post status for a post would look something like 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(
          'post_status'  => 'draft' ,
        );  
    
        // update the post
        $post_id = wp_insert_post($post); 
        wp_update_post($post);
        
        return $post_id;
      }
      
      add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
      
    ?>