In case anyone needs this, here is my solution: if ($_FILES) { function insert_attachment($file_handler, $post_id, $setthumb = ‘false’) { if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false(); require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’); $attach_id = media_handle_upload( $file_handler, $post_id ); //get url $attachment_url = wp_get_attachment_url($attach_id); add_post_meta($post_id, ‘_file_paths’, $attachment_url); $attachment_data = … Read more