title: Add attachment metadata after wp_insert_attachment()
body: <p>I am writing a plugin that saves email attachments to a custom disk folder and then adds them as attachments to a custom post type. This all works correctly so far, but I need to save a couple of metadata values. The metadata will always be the same (so far) and it needs to be on any attachment filetype (.zip, .jpg, .txt, etc)</p>
  
  <p>Can anyone tell me how to add a metadata key/value in this code:</p>
  
  <pre><code>$filename = $attachment['filename'];
  $mimetype = $attachment['mimetype'];
  $data     = $attachment['data'];
  
  $upload = wp_upload_bits( $filename, null, $data );
  
  if ( ! $upload['error'] ) {
  
      $attachment_data = array(
          'guid'           =&gt; trailingslashit( $upload['url']) . basename( $filename ),
          'post_mime_type' =&gt; $mimetype,
          'post_parent'    =&gt; $post_id,
          'post_title'     =&gt; preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
          'post_content'   =&gt; '',
          'post_status'    =&gt; 'inherit',
      );
  
  
      $attachment_id = wp_insert_attachment( $attachment_data, $upload['file'], $post_id );
  
      if ( is_wp_error( $attachment_id ) ) {
  
          return false;
  
      } else {
  
          $attach_data = wp_generate_attachment_metadata( $attachment_id, $upload['file'] );
          wp_update_attachment_metadata( $attachment_id, $attach_data );
  
          return true;
  
      }
  }
  </code></pre>
  
  <p>$attach_data above always returns empty.</p>