I've just noticed that all of my values in this array, which are either integer or null, when I use update_post_meta
, it stores both the integer and null value as a string, rather than an object.
When I var_dump on the output from get_post_meta, I get this:
array (size=1)
0 =>
array (size=5)
0 => string '238' (length=3)
1 => string '234' (length=3)
2 => string 'null' (length=4)
3 => string 'null' (length=4)
4 => string 'null' (length=4)
Why is this, and how can I fix this?
function bv_faq_procedure_meta_box_save($post_id) {
// Check the nonce
if(!isset($_POST['bv_faq_procedure_meta_box_nonce']) || !wp_verify_nonce($_POST['bv_faq_procedure_meta_box_nonce'], basename( __FILE__ ))) {
return;
}
// Check the user's permissions.
if(!current_user_can('edit_post', $post_id)) {
return;
}
$bv_faq_procedures = array(
isset($_POST['bv_faq_procedure_meta_1']) ? $_POST['bv_faq_procedure_meta_1'] : null,
isset($_POST['bv_faq_procedure_meta_2']) ? $_POST['bv_faq_procedure_meta_2'] : null,
isset($_POST['bv_faq_procedure_meta_3']) ? $_POST['bv_faq_procedure_meta_3'] : null,
isset($_POST['bv_faq_procedure_meta_4']) ? $_POST['bv_faq_procedure_meta_4'] : null,
isset($_POST['bv_faq_procedure_meta_5']) ? $_POST['bv_faq_procedure_meta_5'] : null
);
// Save meta
if(isset($_POST['bv_faq_procedure_meta_1']) || isset($_POST['bv_faq_procedure_meta_2']) || isset($_POST['bv_faq_procedure_meta_3']) || isset($_POST['bv_faq_procedure_meta_4']) || isset($_POST['bv_faq_procedure_meta_5'])) {
update_post_meta($post_id, 'Procedure', $bv_faq_procedures);
} else {
// delete data
delete_post_meta($post_id, 'Procedure');
}
}
add_action('save_post_faq', 'bv_faq_procedure_meta_box_save', 10, 2 );