Cloning Posts with serialized post meta
-
hi there,
I was looking at your code to see how you clone/duplicate posts because I wanted to do something similar in my plugin.
I noticed an issue when posts are cloned with serialized post meta, or when the post meta was stored as an array (which is serialized by WP).
By adding a small check when you loop through the meta, it will also handle serialized arrays correctly:
foreach ( $meta as $key => $val ) { $meta_value = $val[0]; if ( is_serialized( $meta_value ) ) { $meta_value = @maybe_unserialize( $meta_value ); } update_post_meta( $new_id, $key, $meta_value ); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Cloning Posts with serialized post meta’ is closed to new replies.