Created
          March 19, 2021 10:42 
        
      - 
      
- 
        Save seebeen/1ad42438922e08f4c441d153c40fc2ee to your computer and use it in GitHub Desktop. 
    WordPress add attachment to auto-save
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| add_action('save_post', 'add_attachment_to_autosave'); | |
| function add_attachment_to_autosave( $post ) | |
| { | |
| if( !wp_is_post_autosave($post) ) : | |
| return; | |
| endif; | |
| if ( get_post_meta($post->ID, '_thumbnail_id', true) ) : | |
| return; | |
| endif; | |
| $attachment_id = 999; | |
| add_post_meta($post->ID, '_thumbnail_id', $attachment_id); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment