content-type-standards icon indicating copy to clipboard operation
content-type-standards copied to clipboard

Tool for migrating old metadata to new metadata IDs

Open bryceadams opened this issue 10 years ago • 3 comments

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.

bryceadams avatar Aug 31 '14 04:08 bryceadams

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

ChaseWiseman avatar Sep 05 '14 22:09 ChaseWiseman

Sounds like a nice idea. Two more ideas that come to my mind when reading this:

  • Have these migrations as WP-CLI commands
  • Some further help with migration if we're not just talking pure metadata but have this e.g. registered via ACF

kraftner avatar May 04 '15 14:05 kraftner

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'" );

justintadlock avatar Jul 09 '15 22:07 justintadlock