Skip to main content
Tweeted twitter.com/StackWordPress/status/1222263256024342528
added 2 characters in body; edited title
Source Link
butlerblog
  • 5.1k
  • 3
  • 26
  • 42

sanitizing Sanitizing integer input for update_post_meta

When updating a post meta where the input will be always an integer, should iI use (int) or is there anya WordPress function for that (eg. sanitize_text_field) For?

For example:

if(isset($_POST['category_id'])){
    update_post_meta($post->ID, 'category_id', (int)($_POST['category_id']));
}
    

sanitizing integer input for update_post_meta

When updating a post meta where the input will be always an integer, should i use (int) or is there any WordPress function for that (eg. sanitize_text_field) For example

if(isset($_POST['category_id'])){
    update_post_meta($post->ID, 'category_id', (int)($_POST['category_id']));
}
    

Sanitizing integer input for update_post_meta

When updating a post meta where the input will be always an integer, should I use (int) or is there a WordPress function for that (eg. sanitize_text_field)?

For example:

if(isset($_POST['category_id'])){
    update_post_meta($post->ID, 'category_id', (int)($_POST['category_id']));
}
    
Source Link
asam
  • 81
  • 1
  • 1
  • 2

sanitizing integer input for update_post_meta

When updating a post meta where the input will be always an integer, should i use (int) or is there any WordPress function for that (eg. sanitize_text_field) For example

if(isset($_POST['category_id'])){
    update_post_meta($post->ID, 'category_id', (int)($_POST['category_id']));
}