/*
* Delete a metakey and its value from wordpress db based on comparison operator
* $comparison_operator can contain 'Like' or '='
*/
delete_metakey($metakey_to_delete, $comparison_operator);
function delete_metakey($metakey_to_delete, $comparison_operator) {
global $wpdb;
if ($comparison_operator == 'LIKE') {
$mysql_query = "DELETE FROM $wpdb->postmeta WHERE meta_key " . $comparison_operator . " '%" . $metakey_to_delete . "%'";
} elseif ($comparison_operator == '=') {
$mysql_query = "DELETE FROM $wpdb->postmeta WHERE meta_key " . $comparison_operator . " '$metakey_to_delete' ";
}
$wpdb->query($mysql_query);
}