here is how to add [post custom fields] to the duplicated post
-
This is my answer to the question I asked ~year ago, “Can you add [post custom fields] to the duplicated post”
since I didn’t get the answer I forget about it, and because I’m not that expert on WP development I never tried to solve it myself.
Anyway couple minutes ago I was able to solve my issue after asking ChatGPT how to inset costume meta key to a newly created post and here is the code (add it to your them function.php)
function my_custom_function_after_insert_post($post_id, $post, $update) {
if ( !$update ) {
add_post_meta ( $post_id , 'mykey1', "" , true ) ;
add_post_meta ( $post_id , 'mykey2', "" , true ) ;
add_post_meta ( $post_id , 'mykey3', "" , true ) ;
add_post_meta ( $post_id , 'mykey4' , "" , true ) ;
}
}
add_action('wp_insert_post', 'my_custom_function_after_insert_post', 10, 3);
- The topic ‘here is how to add [post custom fields] to the duplicated post’ is closed to new replies.