Created
August 15, 2020 22:25
-
-
Save trvswgnr/2e33d1f11d65b3ace00767fcd078f17c to your computer and use it in GitHub Desktop.
WordPress - Update postkey once
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
function change_postkey_only_once() { | |
$key = 1; | |
$option = 'change_postkey_only_once_' . $key; | |
if ( ! get_option( $option ) ) { | |
global $wpdb; | |
$query = "UPDATE " . $wpdb->prefix . "postmeta | |
SET meta_key = 'new_key_name' | |
WHERE meta_key = 'old_key_name'"; | |
$results = $wpdb->get_results($query, ARRAY_A); | |
return $results; | |
update_option( $option ); | |
} | |
} | |
add_action('admin_init', 'change_postkey_only_once'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment