Created
July 22, 2016 08:02
-
-
Save mustardBees/e45fed6a74aba6dd103aa9cc6e740d7c to your computer and use it in GitHub Desktop.
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 | |
/* | |
Plugin Name: Convert SMURF to CMB2 repeatable field groups | |
Plugin URI: http://www.iweb.co.uk/ | |
Description: Go through and zero index each SMURF array. | |
Version: 1.0.0 | |
Author: iWeb | |
Author URI: http://www.iweb.co.uk/ | |
*/ | |
if ( isset( $_GET['fix_smurf'] ) ) { | |
add_action( 'template_redirect', function () { | |
global $wpdb; | |
$results = $wpdb->get_results( | |
" | |
SELECT pm.post_id, pm.meta_value FROM {$wpdb->postmeta} pm | |
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id | |
WHERE pm.meta_key = '_cmb_specifications' | |
" | |
); | |
if ( empty( $results ) ) { | |
die( 'No post meta with that key.' ); | |
} | |
foreach ( $results as $result ) { | |
printf( 'Working on post ID %s:<br>', $result->post_id ); | |
$meta_value = maybe_unserialize( $result->meta_value ); | |
$fixed_meta_value = array_values( $meta_value ); | |
update_post_meta( $result->post_id, '_cmb_specifications', $fixed_meta_value, $meta_value ); | |
} | |
die( 'Done.' ); | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment