-
-
Save rilwis/c107635826ee0f148dede7e374c1d313 to your computer and use it in GitHub Desktop.
Convert cloneable values
This file contains 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 | |
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