Answers for "update the same custom field without duplicates"

0

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) {
            // Fetch array of custom field values
            $postmeta = get_post_meta($postinfo->ID, $key);

            if (!empty($postmeta) ) {
                // Delete the custom field for this post (all occurrences)
                delete_post_meta($postinfo->ID, $key);

                // Insert one and only one custom field
                update_post_meta($postinfo->ID, $key, $postmeta[0]);
            }
        }
    }
?>
Posted by: Guest on November-30-2020
0

update the same custom field without duplicates

add_post_meta( $post->ID, 'my_foo_bar', 'value', true );
Posted by: Guest on November-30-2020

Code answers related to "update the same custom field without duplicates"

Browse Popular Code Answers by Language