You should always use update_post_meta()
function because if the term doesn’t exist it will make a call to the add_post_meta()
automatically.
The same goes for update_user_meta()
.
Example if you want to add the meta “City” but you don’t have it in the db you simply make a update_post_meta($city)
and in $city
you need the post_id
and the new value for city
.
Like that :
$city = array(
'post_id' => $post_id,
'city' => 'Melbourne'
);
For more information refer to : codex.wordpress.org/Function_Reference/update_post_meta
Related Posts:
- What is the index [0] for on post meta fields?
- Custom field metabox not showing in back-end
- How to hide meta box values from custom fields list?
- Create meta boxes that don’t show in custom fields
- Custom fields to save multiple values
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- Create Multiple File Upload Metabox in WordPress
- Button inside Custom Meta Box triggering the Update Button
- Why is my Custom Meta Box Field Inputs NOT saving?
- get_posts in meta box dropdown not showing latest posts
- How can you include custom post meta in search without calling each key?
- Display Custom Meta Box Field Only If Value is Present
- shortcode in a custom metabox
- Problem with saving large amount of data in postmeta/usermeta
- Move Title and the Content WYSIWYG editor position
- How to validate select field in post meta?
- How to use media upload on metabox post page without breaking TinyMCE?
- Let’s Create Custom Field Template Documentation
- How add multiple wp_editor_box to new post
- Meta box values are displayed on Custom Fields list. Is it possible to hide them?
- If metabox has content display content
- put saved metabox values back into fields and then display on the front end
- How to improve my non-unique metadata MySQL entries?
- Set class if a meta value is set within post archive
- WordPress Blocks, setAttributes not saving
- Allow HTML in Custom Metabox area
- Custom field metabox not showing in back-end
- Save, update, get and sanitize post meta as HTML not plain
- Create Meta boxes dynamically
- Get meta value when the page is a blog archive
- Can’t save meta field value if the title not set
- Display Data From This Custom Media Upload Meta Box?
- When post is updated, custom metadata in text area field is overwritten
- wp_postmeta are updated for only one page
- When editing a post with a custom meta box the values aren’t displaying correctly
- How to add new Metadata options (Date, Author, etc.) for Posts?
- Saving multiple custom meta box fields
- How to get custom post meta using REST API
- Individual Widgets per Page
- Using get_post_meta with new_to_publish
- How to add add_meta_box to specific Page Template?
- Can I count the number of users matching a value in a multiple value key?
- Auto sort the wp-admin post list by a meta key
- Adding another state (spam, reject, approve) to wordpress comments?
- extend Meta Box / Document Panel
- Add multiple images to a page sidebar
- Get updated meta data after save_post hook
- Save HTML formatted data to post meta using add_post_meta()
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- Metabox nonce PHP notice
- TinyMCE in Custom Metabox not loaded after upgrading from WP 3.1.4 to WP 3.2
- How to break meta values into different items and avoid duplicates?
- ajax delete value from custom field array
- add meta box using function.php
- Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
- all tincymce’s switch when updating page after changing from html to text in custom metabox
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How to display Meta Field Value?
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- Can’t get post ID using wp_insert_post_data
- Better Method for Multiple Meta Boxes
- How to create a shortcode to print specific values stored in a post meta array?
- Add custom field to all posts in specific post_type
- How to load an assets based on custom field value?
- Custom WP_Query for WordPress Search Results with meta_query
- Unique meta_key with array value vs repeated meta_key with single values
- Set checkbox as checked by default in a metabox
- Singleton Custom Field (Meta Box)
- wordpress custom loop ascending descending posts by custom field
- Custom metabox not displaying multiselect data in edit mode
- How to display childrens custom fields?
- Hide custom fields when empty
- Save all the post tags inside a custom field
- Displaying pages with a specific custom meta
- How can I output WPAlchemy repeating fields meta values in my page template?
- How to validation for sanitize_URL?
- Gravity Forms Update post meta from template [closed]
- Custom metabox not working
- How to get custom image field of specific post id
- Meta Box Plugin Cloned Fields – Multiple Foreach values
- Display metabox title for custom fields with values
- How can I change author of posts to the value of one of the custom field of the posts?
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- Adding Custom Metadata to my Archive/Posts page
- Add forms dynamically in admin pages?
- Saving Custom Field that includes Quotation marks
- Post meta data not showing in frontend, until hitting ‘update’ button
- searching by keywords in post’s metas or pagination links problem
- update meta field value after
- If metabox fields has content display content
- Delete custom post type metadata without deleting the post in admin area
- Echo out custom fields in comments
- Search one custom field?
- Save values generated via API as custom meta fields
- update_post_meta not working in action hook
- How do i output images from URL’s added to the same custom field key
- add multiple values (array) to post meta_input
- Site uses wpdb to fetch meta_keys but just displays first meta_key from a page (the post uses the same meta_key “filmmaker” more than once)