Use update_post_meta()
, because if the meta key already exists add_post_meta()
will do nothing if $unique
is true
and otherwise won’t update neither, while update_post_meta()
, well, it will update the value of a existing field or create it, if it doesn’t exist yet.
Related Posts:
- Get updated post meta on save_post action?
- wp_insert_post inside save_post adds wrong metadata to inserted post
- Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
- Execute action after post is saved with all related post_meta records (data)
- advanced custom fields update_field for field type: Taxonomy
- Content hooks vs User hooks
- Restrict post edit/delete based on user ID and custom field
- Add post meta based on another post meta value before publish post
- Correct processing of `$_POST`, following WordPress Coding Standards
- update_post_meta() whenever custom post type is updated
- Delete post meta conditionally after save post
- Post IDs missing on delete_postmeta action hook
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- Compare old meta with new post meta
- Save post meta foreach loop
- Update post meta within save_post action
- wordpress is_front_page() issue
- How can I get some of a posts meta data whilst it is still inserting?
- troubles with get_post_meta (and saving it)
- Insert Custom Field Value
- Meta keys won’t add using wp_insert_post
- Get post meta after insert post
- How to call get_post()?
- Update post_meta post_name with the post ID from wp_insert_post after user register
- post_title in save_post action
- php wp_insert data on front using a form
- WooCommerce wp_insert_post action firing on every save
- Auto save title as custom meta field value
- Remove action of an external plugin after checking if custom post meta is set
- Save frontend submission form field as custom field
- get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post
- if condition from post_meta not working in save_post
- Getting author’s nickname as meta value
- Get post meta in function hooked to transition_post_status
- How do I retrieve the slug of the current page?
- Most efficient way to get posts with postmeta
- Get posts by meta value
- Why does save_post action fire when creating a new post?
- Explanation of update_post_(meta/term)_cache
- what is correct way to hook when update post
- How to extract data from a post meta serialized array?
- How to update custom fields using the wp_insert_post() function?
- Attaching taxonomy data to post with wp_insert_post
- Passing error/warning messages from a meta box to “admin_notices”
- How to save an array with one metakey in postmeta?
- WordPress is stripping escape backslashes from JSON strings in post_meta
- How can I get the post ID from a WP_Query loop?
- What is “meta_input” parameter in wp_insert_post() used for?
- How to update_post_meta value as array
- Adding meta tag without plugin
- What’s the point of get_post_meta’s $single param?
- What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
- Return $post_id when DOING_AUTOSAVE?
- How to edit a post meta data in a Gutenberg Block?
- Sanitizing integer input for update_post_meta
- post formats – how to switch meta boxes when changing format?
- Why is there both a save_post and wp_insert_post action?
- update_post_meta and update_field ony working when saving the post
- Lack of composite indexes for meta tables
- Get a single post by a unique meta value
- trigger save_post event programmatically
- if get_post_meta is empty do something
- Unable to prevent function using save_post firing twice
- Create posts on user registration
- How we get_post_meta without post id
- How get post id from meta value
- What is the code to get the download link for a product in WooCommerce?
- Safe to delete blank postmeta?
- update_post_meta not saving when value is zero
- Custom post type save_post action not firing
- Meta compare with date (stored as string) not working
- When and Where to use wp_insert_post()
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- Trying to get custom post meta through Jetpack JSON API [closed]
- How to update/insert custom field(post meta) data with wordpress REST API?
- save_post + insert_post = infinite loop
- get_post_meta returning empty string when data shows in the database
- publish_post action hook doesn’t give post_meta_data
- Remove WordPress.org Meta link
- Remove post meta keys
- How to access the post meta of a post that has just been published?
- Why time functions show invalid time zone when using ‘c’ time format?
- A Post is saved twice or more during add_action(save_post)
- Why is get_post_meta returning an array when I specify it as single?
- How to update/delete array in post meta value?
- How to get all term meta for a taxonomy – getting term_meta for taxonomy
- wp_insert_post() getting slower the more posts
- Adding an assisting editor box to Post page
- Why can’t I hook into save_posts after admin_init?
- Action ‘save_post’ not working for quick edit
- Get updated meta data after save_post hook
- Manipulating post meta in the customizer
- delete unused postmeta
- Should I sanitize custom post meta if it is going to be escaped later?
- Change meta tags programatically
- How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
- Front-end update_post_meta snippet displays white screen?
- Query between two meta values?
- Save both current and new version of post meta
- Get Advanced Custom Fields values before saving [closed]