title: Custom upload directory to also change attachment meta
body: <p>Please see below the filter I am using to change the upload directory for my custom post-type.</p>
  
  <p>My custom post-type name is 'download'</p>
  
  <p>My new directory for uploads in my custom post-type 'download' is now... <strong>wp-content/downloads/</strong></p>
  
  <p>The problem is in doing this, is that I my image thumbnails are missing because the attachment meta data is looking for the thumbnail in the original directory <strong>wp-content/uploads/</strong>.</p>
  
  <p>How can I adjust my filter or fix the problem so the attachment data for this custom post-type only uses the new directory <strong>wp-content/downloads/</strong></p>
  
  <p>Thanks is advance for any advice or help.</p>
  
  <p>Josh</p>
  
  <pre><code>add_filter( 'upload_dir', 'my_custom_upload_dir' );
  function my_custom_upload_dir( $default_dir ) {
  
      if ( ! isset( $_POST['post_id'] ) || $_POST['post_id'] &lt; 0 )
      return $default_dir;
      if ( get_post_type( $_POST['post_id'] ) != 'download' )
      return $default_dir;
  
      $dir = WP_CONTENT_DIR . '/downloads';
      $url = WP_CONTENT_URL . '/downloads';
  
      $bdir = $dir;
      $burl = $url;
      $subdir = '';
  
      if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
  
          $time = current_time( 'mysql' );
          $y = substr( $time, 0, 4 );
          $m = substr( $time, 5, 2 );
          $subdir = "/$y/$m";
  
      }   
  
      $dir .= $subdir;
      $url .= $subdir;
  
      $custom_dir = array( 
  
          'path'    =&gt; $dir,
          'url'     =&gt; $url, 
          'subdir'  =&gt; $subdir, 
          'basedir' =&gt; $bdir, 
          'baseurl' =&gt; $burl,
          'error'   =&gt; false, 
  
      );
  
      return $custom_dir;
  
  }
  </code></pre>