Free tools Windows power users keep installed
One-click scans. No signup required.
Post meta is structured key-value data attached to a WordPress post, page, or other post type. Use the core metadata functions to read and change it; register custom keys when their type, access rules, or availability in the REST API or block editor matters. A key can have multiple values unless you enforce uniqueness, so choose the API and registration settings to match the data you intend to store.
What post meta stores
WordPress metadata associates a key with a value on an object. For posts and other post types, the standard table is wp_postmeta; installations may use a different database table prefix. Multiple metadata entries can have the same key and different values. In the dashboard, post metadata is commonly called “Custom Fields”; developers often call it post meta. See the WordPress Metadata API handbook.
As an Amazon Associate I earn from qualifying purchases.
Meta is useful for information that extends a post without changing its main content—for example, a structured value used by a theme, plugin, editor, or integration. The key names the field; the value holds its data. PHP arrays and objects can be stored as serializable values, but their shape and intended use should be planned before exposing them to other systems.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Choose the core function for the operation
| Need | Function | Behavior to account for |
|---|---|---|
| Add a value | add_post_meta( $post_id, $meta_key, $meta_value, $unique ) |
By default, a same-key value can be added even when that key already exists. Set $unique to true to prevent adding another value for that key. |
| Read values | get_post_meta() |
Retrieve one value or all values according to the field’s stored shape and intended cardinality. |
| Set or replace a value | update_post_meta( $post_id, $meta_key, $meta_value, $prev_value ) |
Updates matching metadata; if the key is absent, it adds the value. A false return can mean failure or that the new value matches the existing value. |
| Remove metadata | delete_post_meta() |
Deletes metadata for the post. |
| Check whether a key exists | metadata_exists( 'post', $post_id, $meta_key ) |
Distinguishes a missing key from a key that exists with an empty value. |
Function references: add_post_meta(), update_post_meta(), and metadata_exists().
Decide whether duplicate values are valid
Use add_post_meta() with $unique set to true when a key is intended to have only one entry and you want to block another add for that key. If a field is inherently repeatable, allow multiple entries and make the read and update behavior consistent with that choice. Uniqueness on an add call is not a substitute for understanding the existing data or for choosing the right registration cardinality.
Interpret update results correctly
update_post_meta() can add a value when no matching key exists. Do not treat every false return as proof that nothing was stored: the function can also return false when the proposed value equals the existing value. If the distinction matters to your code, check the data or key state rather than relying on that return value alone.
Rank #2
Account for slashes in stored values
The documented behavior of add_post_meta() and update_post_meta() includes stripping slashes from values before storage. This matters for strings such as JSON that contain escaped characters. The update_post_meta() reference documents wp_slash() as a workaround for that case. Do not add slashes indiscriminately; use the workaround only when the value’s escaping requires it.
Recommended Free Tools
Register custom metadata for a post type
For a custom key intended for a particular post type, use register_post_meta( $post_type, $meta_key, $args ). It scopes registration to that post type and delegates to register_meta(). Registration describes the field’s behavior instead of merely storing a value. See the register_post_meta() and register_meta() references.
Rank #3
- 💌HAPPY SWEETEST DAY - Spread feel-good vibes and love on Sweetest Day with this keepsake for your special person! Just customize it with your names, avatars, and a photo.
- MAKE THEIR DAY BRIGHTER - Capture your sweetest moments with the ultimate way to say “I care.”
- OUR STORY IS THE CUTEST - The fun doesn't stop here – jot down a heartfelt message or share your love story on the back cover!
- BOOK OF US - This 32-page, 8.5 by 8.5-inch keepsake features high-quality illustrations with perfect pops of color that match the cover color. Made in the USA and perfect for adults all ages.
- SHOP WITH CONFIDENCE - Your order will be made with a commitment to premium quality and the recipient will love it! Our goal is to uphold your reputation for giving distinctive, customized gifts that connect people one page at a time.
Set registration arguments according to the field’s data and users. Relevant choices include:
typeandsingleto describe the value’s type and whether it is a single value.defaultfor a default value where appropriate.sanitize_callbackto validate or sanitize values as they are handled.auth_callbackto control authorization.show_in_restwhen the field should be available through the REST API.- Revision-related behavior when metadata should participate in post revisions.
Do not expose private or sensitive values simply because registration makes it convenient. Decide who needs to read or write the field, how values should be sanitized, and whether its lifecycle should follow post revisions.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Expose metadata through the REST API
To make registered metadata available in REST post responses and writable through the API, enable show_in_rest in its registration. The field appears in the post response’s meta object. For a custom post type, the post type must also support custom-fields. WordPress explains response extension in the REST API handbook.
Describe structured values with a schema
If the registered value type is object or array, provide a schema that defines the allowed structure. REST-exposed arrays specifically require an item schema. Without a schema that matches the intended shape, the API does not have the information it needs to describe and validate that structured field reliably.
Best Value
- HAPPY SWEETEST DAY - Spread feel-good vibes and love on Sweetest Day with this keepsake for your special person! Just customize it with your names, avatars, and a photo.
- MAKE THEIR DAY BRIGHTER - Capture your sweetest moments with the ultimate way to say “I care.”
- OUR STORY IS THE CUTEST - The fun doesn't stop here – jot down a heartfelt message or share your love story on the back cover!
- BOOK OF US - This 32-page, 8.5 by 8.5-inch keepsake features high-quality illustrations with perfect pops of color that match the cover color. Made in the USA and perfect for adults all ages.
- SHOP WITH CONFIDENCE - Your order will be made with a commitment to premium quality and the recipient will love it! Our goal is to uphold your reputation for giving distinctive, customized gifts that connect people one page at a time.
Use the same care in the block editor
The WordPress tutorial Creating a custom block that stores post meta demonstrates registered metadata exposed through REST with a sanitization callback; its example post type includes custom-fields support. Treat it as an illustration of the requirements, not a requirement to copy its exact implementation into every project.
Quick Recap
A practical decision checklist
- Scope: Is the key specific to one post type? If so, register it with
register_post_meta(). - Shape: Is it one scalar, a repeatable value, an object, or an array? Match the stored structure,
singlesetting, and REST schema. - Access path: Will code use PHP metadata functions, or must an editor or integration read and write it through REST?
- Access control: Which values can users read or change? Choose sanitization and authorization behavior accordingly.
- Lifecycle: Should the metadata be included in revisions, and does the post type support the behavior your use case needs?
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




