Created
July 29, 2012 14:38
-
-
Save zanematthew/3199265 to your computer and use it in GitHub Desktop.
WordPress Update Meta Key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please don't do this. It's vulnerable to SQL injection attacks. Please use $wpdb->prepare() to escape input parameters.