Specifying meta field’s column type in Database using add_post_meta

When you use add_post_meta, no column in database is created. All post meta data is stored in wp_postmeta table (https://codex.wordpress.org/Database_Description#Table:_wp_postmeta). Here’s the structure of that table:

enter image description here

  • post_id is the ID of post that this meta data is assigned to
  • meta_key is the key of meta (in your case favourite_fruit_code)
  • meta_value is the value of that meta

So you’re not able to set the type of column, because there is no column, and you’re not able to set the type of value, because all values are stored as LONGTEXT.

On the other hand, there is no need for setting the type of this column. You should sanitize and validate the values before setting them, and you can use meta_type in your meta query, so the values are compared correctly.