Here’s a piece of code similar to what I have used to fix the problem once imported the data:
<?php
define('MY_METABOX_ID', 'my_metabox_id');
define('MY_METABOX_PREFIX', 'my_metabox_prefix_');
define('MY_CUSTOM_POST_TYPE', 'my_custom_post_type');
// Include WordPress
define('WP_USE_THEMES', false);
define('WP_DEBUG', 1);
require_once('../wp-load.php');
// extract all MY_CUSTOM_POST_TYPE posts
$q = new WP_Query('post_type=" . MY_CUSTOM_POST_TYPE . "&nopaging=true');
// for each post
while($q->have_posts()) {
$q->next_post();
$p = $q->post;
$id = $p->ID;
// check if the field already exists, take action only if it does not
if (!get_post_meta($id, MY_METABOX_ID . '_fields', true)) {
// crete the content
$fields = array(
MY_METABOX_PREFIX . 'field1',
MY_METABOX_PREFIX . 'field2',
MY_METABOX_PREFIX . 'field3',
);
//add the meta field
add_post_meta($id, MY_METABOX_ID . '_fields', $fields);
}
}
echo 'DONE!';