title: Custom post type image upload with meta box
body: <p>I can't find my attached image in custom post type.
  The code in functions.php</p>
  
  <pre><code>$prefix = 'custom_';
  $custom_meta_fields = array(
  
      array(
          //'label'   =&gt; 'Textarea',
          'desc'  =&gt; 'A description for the field.',
          'id'    =&gt; $prefix.'textarea',
          'type'  =&gt; 'textarea'
      )
  );
  
  // Default metabox for custom post types.
  function avz_custom_meta_box() {
  
     // $post_types = get_post_types( array( 'public' =&gt; true ) );
     $post_types = get_post_types();
      foreach ( $post_types as $post_type ) {
          if ( $post_type == 'page' || $post_type =='post' )
              continue;
          add_meta_box(
          $prefix.'image', 
          'Header Image Upload Box', 
          'show_avz_custom_meta_box', 
          $post_type, 
          'normal', 
          'high' );
      }
  
  }
  add_action('add_meta_boxes', 'avz_custom_meta_box');
  
  function show_avz_custom_meta_box() {
      global $avz_custom_meta_box_fields, $post;
      // Use nonce for verification
      echo '&lt;input type="hidden" name="avz_custom_meta_box_fields_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" /&gt;';
  
      // Begin the field table and loop
      echo '&lt;table class="form-table"&gt;';
      foreach ($avz_custom_meta_box_fields as $field) {
          // get value of this field if it exists for this post
          $meta = get_post_meta($post-&gt;ID, $field['id'], true);
          // begin a table row with
          echo '&lt;tr&gt;
                  &lt;td&gt;';
                  switch($field['type']) {
                      case 'image':
                          $image = get_template_directory_uri().'/images/image.png';  
                          echo '&lt;span class="custom_default_image" style="display:none"&gt;'.$image.'&lt;/span&gt;';
                          if ($meta) { $image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0]; }               
                          echo    '&lt;input name="'.$field['id'].'" type="hidden" class="custom_upload_image" value="'.$meta.'" /&gt;
                                      &lt;img src="'.$image.'" class="custom_preview_image" alt="" /&gt;&lt;br /&gt;
                                          &lt;input class="custom_upload_image_button button" type="button" value="Choose Image" /&gt;
                                          &lt;small&gt;&amp;nbsp;&lt;a href="#" class="custom_clear_image_button"&gt;Remove Image&lt;/a&gt;&lt;/small&gt;
                                          &lt;br clear="all" /&gt;&lt;span class="description"&gt;'.$field['desc'].'&lt;/span&gt;';
                      break;
  
                  } //end switch
          echo '&lt;/td&gt;&lt;/tr&gt;';
      } // end foreach
      echo '&lt;/table&gt;'; // end table
  }
  
  // Save the Data
  function save_multiBox_custom_meta($post_id) {
      global $avz_custom_meta_box_fields;
  
      // verify nonce
      if (!wp_verify_nonce($_POST['avz_custom_meta_box_fields_nonce'], basename(__FILE__))) 
          return $post_id;
      // check autosave
      if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE)
          return $post_id;
      // check permissions
      if ('page' == $_POST['post_type']) {
          if (!current_user_can('edit_page', $post_id))
              return $post_id;
          } elseif (!current_user_can('edit_post', $post_id)) {
              return $post_id;
      }
  
      // loop through fields and save the data
      foreach ($avz_custom_meta_box_fields as $field) {
          if($field['type'] == 'tax_select') continue;
          $old = get_post_meta($post_id, $field['id'], true);
          $new = $_POST[$field['id']];
          if ($new &amp;&amp; $new != $old) {
              update_post_meta($post_id, $field['id'], $new);
          } elseif ('' == $new &amp;&amp; $old) {
              delete_post_meta($post_id, $field['id'], $old);
          }
      } // enf foreach
  
      // save taxonomies
      $post = get_post($post_id);
      $category = $_POST['category'];
      wp_set_object_terms( $post_id, $category, 'category' );
  }
  add_action('save_post', 'save_multiBox_custom_meta');
  </code></pre>
  
  <p>And in single.php </p>
  
  <pre><code>if( $image_upload_id = get_post_meta($post-&gt;ID, $field['custom_image'], true)){
      $img = $image_upload_id ['custom_image'][0];
      echo wp_get_attachment_image($img, 'full'); 
  }
  </code></pre>
  
  <p>But can't find attached image.
  In admin uploaded image show but in post page not showing.</p>