Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created July 29, 2012 14:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zanematthew/3199265 to your computer and use it in GitHub Desktop.
Save zanematthew/3199265 to your computer and use it in GitHub Desktop.
WordPress Update Meta Key
<?php
/**
* Rename meta keys
* Usage: update_meta_key( 'old_key', 'new_key');
*/
function update_meta_key( $old_key=null, $new_key=null ){
global $wpdb;
$query = "UPDATE ".$wpdb->prefix."postmeta SET meta_key = '".$new_key."' WHERE meta_key = '".$old_key."'";
$results = $wpdb->get_results( $query, ARRAY_A );
return $results;
}
@alexmangini
Copy link

Thank you. This just saved me big time.

@anthonyeden
Copy link

Please don't do this. It's vulnerable to SQL injection attacks. Please use $wpdb->prepare() to escape input parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment