Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having a problem with saving custom meta box data, when you fill in the textbox and update the post, the data doesn't save in the database.

Here is my code: any help appreciated!

if ( !wp_verify_nonce( isset($_POST['_wpiu_invoice_meta_nonce']), WPIU_RELATIVE )) {
    return $post->ID;
} else { 
    return; 
}

if ( !current_user_can( 'edit_post', $post->ID )){
    return $post->ID;
}//if

$meta = array();

foreach($_POST as $key => $value){
    if(preg_match("/_wpiu_invoice_meta_/i",$key) && $value != ''){
        $meta[$key] = $value;
    }//if   
}//foreach

if(get_post_meta($post->ID, '_wpiu_invoice_meta', true)) { // If the custom field already has a value
    update_post_meta($post->ID, '_wpiu_invoice_meta', $meta);
} else { // If the custom field doesn't have a value
    add_post_meta($post->ID, '_wpiu_invoice_meta', $meta);
}//else

return $post->ID;
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.