I found a function to get the Meta ID by Meta Key. This allowed me to correctly assign my $meta_ID variable, and now the delete ajax button works perfectly.
No need to update the save function at all.
function get_mid_by_key( $post_id, $meta_key ) {
global $wpdb;
$mid = $wpdb->get_var( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta_key) );
if( $mid != '' )
return (int)$mid;
return false;
}
function wp_custom_attachment() {
wp_nonce_field(plugin_basename(__FILE__), 'wp_custom_attachment_nonce');
$html="<p class="description">";
$html .= 'Upload your PDF here.';
$html .= '</p>';
$html .= '<input type="file" id="wp_custom_attachment" name="wp_custom_attachment" value="" size="25" />';
$pdf = get_post_meta(get_the_ID(), 'wp_custom_attachment', true);
if($pdf['url']){
$html .= '<p style="overflow-wrap: break-word;">Current file: ' .$pdf['url'] . '</p>';
}
$meta_id=get_mid_by_key( get_the_ID(), 'wp_custom_attachment' );
$delete_nonce = wp_create_nonce( 'delete-meta_' . $meta_id );
$html.=get_submit_button( __( 'Delete' ), "delete:wp_custom_attachment:meta-{$meta_id}::_ajax_nonce=$delete_nonce deletemeta", "deletemeta[{$meta_id}]", false, array( 'tabindex' => '6' ) );
$html.=wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
echo $html;
} // end wp_custom_attachment