Your current code should be correctly creating the post inside your Products post type.
You’re missing the bit that updates the post meta holding the image. Assuming the meta_key is product_image
, then running this on success should do:
update_post_meta( $pid, 'product_image', $attachment_id );
on a side note: don’t forget to run wp_generate_attachment_metadata and wp_update_attachment_metadata after you upload the image.