update the same custom field without duplicates code example
Example 1: update the same custom field without duplicates
add_post_meta( $post->ID, 'my_foo_bar', 'value', true );
Example 2: update the same custom field without duplicates
<?php
define('WP_USE_THEMES', false);
require('wp-blog-header.php');
define( 'WP_DEBUG_DISPLAY', true );
ini_set( 'display_errors', true );
$allposts = get_posts('numberposts=-1&post_type=post&post_status=any');
$keys = array('podPressPostSpecific', 'aktt_tweeted', 'podPressMedia');
foreach ( $keys as $key ) {
foreach( $allposts as $postinfo) {
$postmeta = get_post_meta($postinfo->ID, $key);
if (!empty($postmeta) ) {
delete_post_meta($postinfo->ID, $key);
update_post_meta($postinfo->ID, $key, $postmeta[0]);
}
}
}
?>