wpseek.com
WordPress开发者和主题制作者的搜索引擎



_wp_copy_post_meta › WordPress Function

Since6.4.0
已弃用n/a
_wp_copy_post_meta ( $source_post_id, $target_post_id, $meta_key )
参数: (3)
  • (int) $source_post_id Post ID to copy meta value(s) from.
    Required: Yes
  • (int) $target_post_id Post ID to copy meta value(s) to.
    Required: Yes
  • (string) $meta_key Meta key to copy.
    Required: Yes
定义在:
文档:

Copy post meta for the given key from one post to another.



源码

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 ) );
	}
}