The solution is using added_post_meta and updated_post_meta hook .
Here is the working code .
add_action( 'added_post_meta', 'add_custom_field_automatically', 10, 4 );
add_action( 'updated_post_meta', 'add_custom_field_automatically', 10, 4 );
function add_custom_field_automatically( $meta_id, $post_id, $meta_key, $meta_value )
{
if ( '_my_meta_key' == $meta_key ) {
add_post_meta($post_id, '_my_new_meta_key', $meta_value.'to something new', true);
}
}
Related Posts:
- Execute action after post is saved with all related post_meta records (data)
- Get updated post meta on save_post action?
- Correct processing of `$_POST`, following WordPress Coding Standards
- Delete post meta conditionally after save post
- Set default Custom Post Meta Value
- Save post meta foreach loop
- troubles with get_post_meta (and saving it)
- wp_insert_post inside save_post adds wrong metadata to inserted post
- post_title in save_post action
- Auto save title as custom meta field value
- 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
- How can I get the post ID from a WP_Query loop?
- How to edit a post meta data in a Gutenberg Block?
- How to update/delete array in post meta value?
- Get updated meta data after save_post hook
- Manipulating post meta in the customizer
- Get Advanced Custom Fields values before saving [closed]
- Why am I getting an infinite loop with have_posts?
- get_post_meta – get a single value
- How to store post meta in an array?
- update_post_meta() not working when used with WordPress action
- Triple meta_key on custom SELECT query
- Get posts by meta value with date
- Identifying Importer Posts
- update_post_meta not working in save_post
- Job of meta_key meta_value fields in database tables
- How to store Gutenberg ColourPicker RGBA as metadata
- Is it possible to update a post meta field through REST API if the format of it when registered is nested?
- How trigger to save post when updating post meta
- Query 2 meta key values and a category
- trying to do if post meta !=0
- Trying to get file name
- how to build (custom) stats for post views, per month
- get_post_meta pagination
- Removing Post Meta from Category Pages?
- Hey, I want the second options. get_post_meta()
- Update post meta in woocommerce order frontend
- echo image caption
- populate post meta in gravity forms [closed]
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- How to display post view count by date, week and month?
- How can I filter posts when the meta_value is a serialize object?
- Get User Post if Private
- How to receive all the meta information of a post ?
- Unknown characters added to meta data values
- Compare old meta with new post meta
- get_post_meta($post->ID) returns empty string when in preview mode of custom post type
- need to add add user names to the post for later retrieval or removal
- Read post meta values, only if posts are public
- Like & Dislike functionality using JavaScript
- Time & Date on Post – Time Ago Custom Function
- Mass removing CSS from 1,700 post [closed]
- How to remove Date from Meta Description on SERP?
- How to display sql query fired by posts_where
- Unfiltered html with update_post_meta
- How to validate select field in post meta?
- get meta value from page query
- Help with Post Meta
- How do I manage custom meta in post revisions in the Block Editor era?
- Generate metadata for cloud images
- Migrating meta value to new meta value
- Insert multiple metas in one time
- How to extract data from a post meta
- count post meta values
- Correct meta of Writing Meta Tags
- Get post_meta from specific post [closed]
- How to add tags to post from frontend?
- Retrieve user_meta and copy to post_meta
- getting the post_id from the post_meta
- How to save HTML data into SQL post_content column
- How to merge the array values in foreach?
- Negative meta_query if storing multiple post_meta values with shared meta_key
- Frontend query and does not need to log in [closed]
- Get data from custom table and update relative post_meta based on meta_key
- How to exclude posts by meta key value in the_post_navigation next prev links?
- update_post_meta not working with transition_comment_status
- Update post meta date always store 1970-01-07
- Is it possible to pass an whole array using custom field in wordpress?
- Attachment metadata has value of ‘1’
- How do I update a specific value within array in a products metadata?
- Optimize WP Meta Query for large amount of post meta?
- rendering open graph meta tags in wordpress
- Restore deleted _thumbnail_id in postmeta table
- Hide the_meta if no value
- php wp_insert data on front using a form
- Updating post_meta when updating a setting with the Settings API
- How to show specific meta keys of all posts in admin panel?
- wp_schedule_event not working
- Media library orphans
- WordPress join posts with meta values of array type
- How to make certain content of the post noindex and no follow. not entire post?
- Export posts with postmeta without ID?
- How can I display my meta value in a textarea? [closed]
- delete blank space in post_meta empty [closed]
- Problem with get_post_meta
- How to show wordpress post in the site based on custom field value?
- Extend file format support for post thumbnails
- Why isn’t my embed_video WYSIWYG field updating when using update_post_meta?