You are not retrieving the saved value for $model
.
$model = get_post_meta( $post_id, 'auction_model', true );
And you should be sanitizing the values upon retrieval, or at least before echoing them:
<?php echo sanitize_text_field( $model ); ?>
You could also check for the value before calling update_post_meta()
upon form submission, unless you intended to run that every time this page is loaded. If nothing else, you can at least check if $_POST
has a value:
if ( isset( $_POST['auction_model'] && ! empty( $_POST['auction_model'] ) ) {
update_post_meta( $post_id, 'auction_model', sanitize_text_field( $_POST['auction_model'] ) );
}
You can also then delete meta if the form field is empty:
else {
delete_post_meta( $post_id, 'auction_model' );
}
You can read more on sanitizing and validating user input here.
And more on the three *_post_meta()
functions mentioned above here: