Skip to content

Instantly share code, notes, and snippets.

@rilwis
Created May 15, 2018 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rilwis/c107635826ee0f148dede7e374c1d313 to your computer and use it in GitHub Desktop.
Save rilwis/c107635826ee0f148dede7e374c1d313 to your computer and use it in GitHub Desktop.
Convert cloneable values
<?php
function prefix_convert( $field_id ) {
$query = new WP_Query( [
'post_type' => 'event',
'posts_per_page' => -1,
] );
if ( ! $query->have_posts() ) {
return;
}
while ( $query->have_posts() ) {
$query->the_post();
$values = rwmb_meta( $field_id );
if ( ! is_array( $values ) || empty( $values ) ) {
continue;
}
delete_post_meta( get_the_ID(), $field_id );
foreach ( $values as $value ) {
add_post_meta( get_the_ID(), $field_id, $value );
}
}
wp_reset_postdata();
}
add_action( 'init', function() {
if ( ! isset( $_GET['unique_key'] ) ) {
return;
}
$field_id = 'start_date';
prefix_convert( $field_id );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment