content-type-standards
content-type-standards copied to clipboard
Tool for migrating old metadata to new metadata IDs
As briefly discussed in #20, it would be useful to have a general function / class for easily moving metadata from their previously used IDs to the new standardised IDs.
A quick function that plugin authors can put into their next update that runs after the plugin is updated would be ideal.
This is a good idea. I wrote this small function as a jumping-off point. Feel free to tear it apart:
https://gist.github.com/ChaseWiseman/3ff6277eb0fb22e20447
Sounds like a nice idea. Two more ideas that come to my mind when reading this:
Here's a little something that might work:
global $wpdb;
// Update post type.
$wpdb->query( "UPDATE {$wpdb->posts} SET post_type = 'standard_post_type' WHERE post_type = 'old_post_type'" );
// Update taxonomy.
$wpdb->query( "UPDATE {$wpdb->term_taxonomy} SET taxonomy = 'standard_taxonomy' WHERE taxonomy = 'old_taxonomy'" );
// Update meta key.
$wpdb->query( "UPDATE {$wpdb->postmeta} SET meta_key = 'standard_meta_key' WHERE meta_key = 'old_meta_key'" );