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:
post_id
is the ID of post that this meta data is assigned tometa_key
is the key of meta (in your casefavourite_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.
Related Posts:
- Right way of storing large number of custom post fields
- Custom post type or just use custom fields
- Using posts and postmeta table to store custom Address Book Plugin data
- WP All Import – Using Xpath to set a select value
- Sorting custom post type columns with external data and without meta values
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Importing Data from a Non-WordPress database, into WP
- Ideas to connect external database table to wordpress posts as custom field source
- delete duplicate meta_value with same post_id
- Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
- when looping through custom post data not appearing
- custom post types, custom fields and normalization
- How to replicate data storage and querying using WordPress. Custom posts/fields or Custom db tables?
- Confused about where to store my data
- Populate custom post type/custom fields from an external database
- Automatically convert standard posts with custom fields to custom post types
- How to enable the user to add value through the admin panel?
- Displaying database table in backend of wordpress
- Custom Post Type Data in Sidebar widgets?
- Custom Post Types, or completely custom?
- Hide custom post type field from author?
- Many to Many Relationship between Two Custom Post Types
- Sorting a query by custom field date
- wordpress plugin error handling
- Creating Photo Gallery System with Custom Post Type
- Set post title from two meta fields
- How to sort CPT by custom meta value (date), and return posts month by month
- Trying to save custom post type from frontend partially working
- Custom Taxonomy order by Custom Field
- Comparing timestamps in meta query doesn’t work
- Is there any performance consideration when using Custom Post Types?
- Custom Post Type Navigation on Custom Field
- how to interconnect custom post types?
- Saving Custom Post types and fields to a custom table
- Adding dropdown select meta box to custom post type – seems restAPI is interfering
- Filter custom posts using auto populated dropdown selectors
- Querying Two Custom Post Types with OR Not Working
- How can I get the number of custom post type posts that have a specific attachment image set?
- Add custom field to Posts and sort by it
- Two Custom Post Types Many to Many Relationship
- Show image gallery from a custom field
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- filter custom post in rest api with custom function
- Custom Fields for Custom Post [closed]
- Is there any way to add a “custom field” to the CPT archive page?
- Organize WordPress site, so it can maintain with huge database
- don’t publish custom post type post if a meta data field isn’t valid
- WebP Fallback for Inline Background Image in Style Attribute
- How can meta boxes be added to “unknown” custom posts?
- Custom “radio button meta box” not saving correctly
- Check if post with same meta value exists
- custom post data – how to
- How to get a custom type post data when it has a connection with another custom type post?
- WP_Query orderby not work with meta_key
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- How do I replace the post title with a custom field?
- Custom Post type loop with ACF not displaying properly
- Reusable metabox backend and frontend
- How to display wp_post by custom field value?
- How can I output WPAlchemy repeating fields meta values in my page template?
- WordPress as a frontend website for iOS app [closed]
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- Custom post types category
- “Custom Field” to Excerpt field” for pages? [closed]
- How to import database table as custom post type and custom fields?
- Custom Taxonomy dont save in a frontend form for post a custom post
- Update custom field value
- Insert custom fields to a custom post type
- Fill custom fields when saving custom post types
- Should i use custom post type for a custom footer?
- Use Gravity Forms and a Shopping Cart for output to Freshbooks for an Estimate [closed]
- A sports wordpress website
- Migrate Custom Post Type with Custom Fields data and parent child order
- Custom taxonomy terms as children of multiple custom post types
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- wp_set_object_terms creates taxonomies but does not add custom posts to it
- How to access repeater field of a custom field?
- PHP Warning with Custom Fields
- Custom post types & Pages hierarchy – Error 404
- filter rest api post by a acf filed
- How to prepend text to custom field value A, but only if custom field value B matches a certain string?
- Custom post type that lets users create a set of posts?
- How do I extract the contents of a CPT’s custom field for all posts?
- Delete custom post type metadata without deleting the post in admin area
- Creating multiple CPT posts from one Gravity form
- Function not pulling image or text from custom post type
- Order Custom Posts by Several Fields
- Custom field totals
- Repeatable custom meta select boxes
- 404 on Pages for Custom Post Type & Query_Posts
- Types plugin isn’t compatible with my custom post type
- Show Posts in Vertical Tabs with Scrollbar
- How do I filter a custom post type loop by a field?
- Custom Post type as Taxonomy
- Display div based on Group metabox selection [closed]
- Display ACF object field data using Elementor Custom Query
- Sortable admin columns ordering from custom fields isn’t combine com search and Dropdown filter
- WordPress custom field sorting, weird behavior: the latest post is at the end
- I want to understand plugin implementation of custom posts / taxonomies / metaboxes
- How to consume external API from WordPress post editor and display the response data in the custom field?