It looks like you need to use update_post_meta()
https://codex.wordpress.org/Function_Reference/update_post_meta
Source: WP Codex
The function update_post_meta() updates the value of an existing meta key (custom field) for the specified post.
This may be used in place of add_post_meta() function. The first thing this function will do is make sure that $meta_key already exists on $post_id. If it does not, add_post_meta($post_id, $meta_key, $meta_value) is called instead and its result is returned.
Returns meta_id if the meta doesn’t exist, otherwise returns true on success and false on failure. It also returns false if the value submitted is the same as the value that is already in the database.
Related Posts:
- Custom post meta field effect on the performance on the post
- Difference between meta keys with _ and without _ [duplicate]
- Orderby meta_value only returns posts that have existing meta_key
- What is “meta_input” parameter in wp_insert_post() used for?
- How to enable revisions for post meta data?
- 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
- Allow user to create instances of custom field
- Is there a hook / action that is triggered when adding or removing a post thumbnail?
- passing argument to get_template_part() or a better way to code
- Get updated meta data after save_post hook
- Create meta boxes that don’t show in custom fields
- Ordering posts by anniversary using only day and month
- How to break meta values into different items and avoid duplicates?
- ajax delete value from custom field array
- Save attachment custom fields on front end
- How to use pagination with get_post_meta
- Copying Custom Meta Values from existing post to a duplicate post
- Custom fields: In what order are they saved into the DB?
- Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
- Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
- Custom field value based on other custom field values
- Saving custom image meta fields
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How to display Meta Field Value?
- MySQL query to set wp_postmeta using term_taxonomy_id value
- How to Validate Post Meta type/extension (Video File Image File etc)
- Custom Meta Box not Saving in Posts with Gutenberg Editor
- Combine multiple custom field values into single value
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- How to wrap meta values seperated by comma in ? [closed]
- Bulk remove post meta
- How to create html block to display extra information on woocommerce single product page
- Can’t get post ID using wp_insert_post_data
- Unique Post Meta Values
- Run a check for multiple meta key values
- WordPress Rest API to call page data associate with custom meta
- Hide custom meta data if empty
- 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
- Button inside Custom Meta Box triggering the Update Button
- How to load an assets based on custom field value?
- Custom WP_Query for WordPress Search Results with meta_query
- How can you include custom post meta in search without calling each key?
- Unique meta_key with array value vs repeated meta_key with single values
- Can I access a post meta field before the loop?
- wrap text around custom fields array
- Allow only one post with specific meta value
- Get all the posts where meta field with multiple choice has several values checked
- wordpress custom loop ascending descending posts by custom field
- How to validate select field in post meta?
- How to display childrens custom fields?
- how to display custom fields of post on a web page
- Hide custom fields when empty
- How do I query the title (or handle?) of post meta fieldset (created with Simple Fields Plugin)
- Save all the post tags inside a custom field
- How to fill custom fields with brackets in their key with add_post_meta()?
- How add multiple wp_editor_box to new post
- Update post meta custom field using block editor
- Get custom fields without _edit_last, _edit_lock, _wp_page_template and _visual-subtitle
- Get YouTube video id from url in a custom field
- Related query shows same image in loop
- Why am I getting a “Call to member function format() on a non-object” error?
- Can’t Output get_post_meta?
- put saved metabox values back into fields and then display on the front end
- Modify custom field from front end
- How to get custom image field of specific post id
- Custom Query: query by post custom meta data
- get_post_custom_values problem, please help
- wordpress multi user question
- update_post_meta not working well
- How can I change author of posts to the value of one of the custom field of the posts?
- Custom meta fields and meta keys
- How to improve my non-unique metadata MySQL entries?
- How to add a post’s view count into the WordPress API response
- Can’t set custom meta fields for a post
- 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
- How do I update custom field post meta in frontend post template?
- update meta field value after
- Custom Fields Not Working In Footer
- Query Posts based on custom field value
- Echo out custom fields in comments
- Display Data From This Custom Media Upload Meta Box?
- Save values generated via API as custom meta fields
- Query postmeta values, and return multiple post_titles for common meta value
- When post is updated, custom metadata in text area field is overwritten
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- update_post_meta not working in action hook
- Custom Field: Display only if a specific key is selected outside the loop
- Display meta data from a custom field within plugin Category Grid View Gallery
- When editing a post with a custom meta box the values aren’t displaying correctly
- Hard Define Custom Field Value
- add_post_meta insert null value into Database
- How do i output images from URL’s added to the same custom field key
- Retrieving custom field as shortcode
- 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)