Skip to content

Instantly share code, notes, and snippets.

@trvswgnr
Created August 15, 2020 22:25
Show Gist options
  • Save trvswgnr/2e33d1f11d65b3ace00767fcd078f17c to your computer and use it in GitHub Desktop.
Save trvswgnr/2e33d1f11d65b3ace00767fcd078f17c to your computer and use it in GitHub Desktop.
WordPress - Update postkey once
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