I have code (add custom field to post edit page):
case 'text':
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />', '<br />', $field['desc'];
break;
I save it with the function:
foreach ($meta_box['fields'] as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
Everything works fine. So if field value exist it appear at the field value and if it doesn't exist it update this field with the new value (add to DB).
The trouble come when I want to add value by System with no ability for user to edit it. So I change first code to (add disabled):
<input type="text" disabled name="'
and now users are unable to edit.
At the post-edit-load there is default value in this field (ok) but it doesn't save value to DB. $new = $_POST[$field['id']];
now is empty.
Does someone have idea how to solve it?
Thank you.