Uploaded image not appearing in custom post type

How About you try this code for your attachment

 $uploaded_file = wp_handle_upload( $file, $upload_overrides );
 $attachment = array(
        'post_mime_type' => $uploaded_file['type'],
        'post_title' => preg_replace('/\.[^.]+$/', '', basename( $uploaded_file['file'] ) ),
        'post_content' => '',
        'post_author' => '',
        'post_status' => 'inherit',
        'post_type' => 'attachment',
        'post_parent' => $new_reseller_id,
        'guid' => $uploaded_file['file']
    );
 $attachment_id = wp_insert_attachment( $attachment, $uploaded_file['file'] );
 $attach_data = wp_generate_attachment_metadata( $attachment_id, $uploaded_file['file'] );

 // update the attachment metadata
 wp_update_attachment_metadata( $attachment_id,  $attach_data );
 //Set as thumbnail
 set_post_thumbnail ($new_reseller_id, $attachment_id );

To fetch the post thumbnail

if you are in the loop, then

  the_post_thumbnail

will give you the featured image. otherwise use

   get_the_post_thumbnail ( $new_reseller_id )

Leave a Comment