WordPress not creating image thumbnail

I’ve got a custom upload function on the front end for a custom post type. If i’m on the back end editing the post the featured image shows as attached but in the media library it’s just a default placeholder. Is there something wrong with my image code? It’s like it isn’t’ generating the wordpress thumbnail

$uploaddir = wp_upload_dir();
$file = $placeholder;
$uploadfile_pl = $uploaddir['path'] . '/' . basename( $file['name'] );

move_uploaded_file( $file['tmp_name'] , $uploadfile_pl );
$filename = basename( $uploadfile_pl );

$wp_filetype = wp_check_filetype(basename($filename), null );

$attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => preg_replace('/.[^.]+$/', '', $filename),
    'post_content' => '',
    'post_status' => 'inherit',
    'menu_order' => 1000
);
$attach_id = wp_insert_attachment( $attachment, $uploadfile_pl, $post_id);
require_once( ABSPATH . 'wp-admin/includes/image.php' );

$values = wp_generate_attachment_metadata($attach_id, $uploadfile_pl);
wp_update_attachment_metadata($post_id, $values);

set_post_thumbnail( $post_id, $attach_id ); 

Related posts

1 comment

  1. Figured it out.

    wp_update_attachment_metadata($post_id, $values);
    

    should be

    wp_update_attachment_metadata($attach_id, $values);
    

    Silly typos.

Comments are closed.