i would like to update multipe values of multiple custom fields at the same time , not in array but like this example:

custom_field1 -> value11
custom_field1 -> value12
custom_field1 -> value13
custom_field2 -> value21
custom_field2 -> value22
custom_field2 -> value23

the code i use is:

add_action( 'add_meta_boxes', 'meta_box' );
function so_custom_meta_box($post){
 add_meta_box('meta_box', 'Custom Box', 'meta_box', 'products', 'normal' , 'high');
}
add_action('save_post', 'so_save_metabox');
function meta_box(){ 
    global $post;
    $custom_field1['custom_field1'] = $_POST['custom_field1'];
    foreach ( $custom_field1 as $key => $value ) { 
        if ( get_post_meta( $post->ID, $key, FALSE ) ) { 
            update_post_meta( $post->ID, $key, $value );
        } else {
            add_post_meta( $post->ID, $key, $value );
        }
        if ( !$value ) delete_post_meta( $post->ID, $key );
    }
    $custom_field2['custom_field2'] = $_POST['custom_field2'];
    foreach ( $custom_field2 as $key => $value ) { 
        if ( get_post_meta( $post->ID, $key, FALSE ) ) { 
            update_post_meta( $post->ID, $key, $value );
        } else {
            add_post_meta( $post->ID, $key, $value );
        }
        if ( !$value ) delete_post_meta( $post->ID, $key );
    }
}
function meta_box($post){
    $cf1 = get_post_meta($post->ID, 'custom_field1', true );                
    $cf2 = get_post_meta($post->ID, 'custom_field2', true );
    $i=0;
    foreach ( $parts as $part) {
        echo '<input type="text" name="custom_field1[]" value="'.$cf1[$i].'"><br/>';
        echo '<input type="text" name="custom_field2[]" value="'.$cf2[$i].'"><br/>';
        $i++;
    } 
}

but when i click save , the data is serialized and i can’t use my upload script to add a new custom fields values because some are serialized and the new ones not.

Any help ? thx

Read more here: update multipe custom fields with multiple values


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: