Copy post meta for the given key from one post to another.
Parameters
$source_post_id
intrequired- Post ID to copy meta value(s) from.
$target_post_id
intrequired- Post ID to copy meta value(s) to.
$meta_key
stringrequired- Meta key to copy.
Source
function _wp_copy_post_meta( $source_post_id, $target_post_id, $meta_key ) {
foreach ( get_post_meta( $source_post_id, $meta_key ) as $meta_value ) {
/**
* We use add_metadata() function vs add_post_meta() here
* to allow for a revision post target OR regular post.
*/
add_metadata( 'post', $target_post_id, $meta_key, wp_slash( $meta_value ) );
}
}
Changelog
Version | Description |
---|---|
6.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.