title: WordPress Uploading Thumbnail for Custom Post Meta
body: <p>I have set up a custom post meta field for Thumbnail on each of my posts. This function is being called correctly, and everything works up until the very last line of <code>update_post_meta</code></p>
  
  <p>What's interesting is that I can echo out <code>$imageURL</code> and get the correct address, and the file uploads fine. I can even <code>update_post_meta</code> with any other value whether it be a string, or another variable within the function but as soon as I try to use <code>$imageURL</code> or <code>$uploaded_file['url']</code> it just sets the post meta to a blank string.</p>
  
  <p>I've used this snippet on projects that were developed with WordPress earlier than 3.1, but this one is 3.1. Could that have something to do with it? I kind of doubt it, since this seems to be one of those super weird bugs.</p>
  
  <pre><code>function tcr_save_thumbnail($post_id, $post) {
      if ( !wp_verify_nonce( $_POST['eventmeta_noncename'], plugin_basename(__FILE__) )) {
          return $post-&gt;ID;
      }
  
      if ( !current_user_can( 'edit_post', $post-&gt;ID ))
          return $post-&gt;ID;
  
      if(!empty($_FILES['tcr_thumbnail_meta']['name'])) { //New upload
          require_once( ABSPATH . 'wp-admin/includes/file.php' );
          $override['action'] = 'editpost';
          $uploaded_file = wp_handle_upload($_FILES['tcr_thumbnail_meta'], $override);
  
          $post_id = $post-&gt;ID;
          $attachment = array(
              'post_title' =&gt; $_FILES['tcr_thumbnail_meta']['name'],
              'post_content' =&gt; '',
              'post_type' =&gt; 'attachment',
              'post_parent' =&gt; $post_id,
              'post_mime_type' =&gt; $_FILES['tcr_thumbnail_meta']['type'],
              'guid' =&gt; $uploaded_file['url']
          );
          // Save the data
          $id = wp_insert_attachment( $attachment,$_FILES['tcr_thumbnail_meta'][ 'file' ], $post_id );
          wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $_FILES['tcr_thumbnail_meta']['file'] ) );
          $imageURL = $uploaded_file['url'];
          update_post_meta($post-&gt;ID, "tcr_thumbnail_meta", $imageURL);
      }
  }
  </code></pre>