Skip to content

Commit

Permalink
Merge pull request #192 from wearerequired/fix/delete-meta-on-republish
Browse files Browse the repository at this point in the history
Clear existing meta data to fix rewrite and republish with non-unique meta keys
  • Loading branch information
karlijnbok authored Oct 28, 2021
2 parents 1e014d5 + 9897712 commit 1b790c1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/post-duplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,13 @@ public function copy_post_meta_info( $new_id, $post, $options ) {

foreach ( $meta_keys as $meta_key ) {
$meta_values = \get_post_custom_values( $meta_key, $post->ID );

// Clear existing meta data so that add_post_meta() works properly with non-unique keys.
\delete_post_meta( $new_id, $meta_key );

foreach ( $meta_values as $meta_value ) {
$meta_value = \maybe_unserialize( $meta_value );
\update_post_meta( $new_id, $meta_key, Utils::recursively_slash_strings( $meta_value ) );
\add_post_meta( $new_id, $meta_key, Utils::recursively_slash_strings( $meta_value ) );
}
}
}
Expand Down

0 comments on commit 1b790c1

Please sign in to comment.