Skip to main content
added 188 characters in body
Source Link
iyrin
  • 1.8k
  • 15
  • 21

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.

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']);
}

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.

Source Link
iyrin
  • 1.8k
  • 15
  • 21

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']);
}