Use a conditional statement to check if $_POST['category_id'])
is an integer first. The PHP function is is_int()
1
if(isset($_POST['category_id']) && is_int($_POST['category_id'])){
update_post_meta($post->ID, 'category_id', $_POST['category_id']);
}
You should also trim whitespace on your $_POST data because is_int()
will return false if the string has whitespace2.