[Closed] Duplicate post function for a custom post type generates invalid meta data

Home Support English Support [Closed] Duplicate post function for a custom post type generates invalid meta data

This topic contains 3 replies, has 4 voices, and was last updated by  Paul 1 year ago.

Viewing 4 posts - 1 through 4 (of 4 total)
Author Posts
Author Posts
February 20, 2012 at 11:15 am #48485

Daan

I have a custom post type that has meta data that contains an array.
When I duplicate the post for another language, the custom post meta data is duplicated as a string (double serialized). So when retrieving the meta, I get back a string instead of the (deserialized) array.
I solved it temporarily like this:
<pre>

$packageId = icl_object_id( get_the_ID(), 'package', true );
$packageIncludes = get_post_meta( $packageId, 'package_meta', true );
$packageIncludes = maybe_unserialize( $packageIncludes );

</pre>

February 20, 2012 at 11:28 am #48487

Harshad

Hello Daan,
Thanks for sharing this, I will try to reproduce the same at my end creating a custom post type.
Regards,
Harshad

April 27, 2012 at 9:40 am #57119

Marcin

I've run into the same problem. It seems that more flexible solution is to modify translation-management.class.php, function make_duplicate, just below the comment //copy custom fields. Get_post_custom used here returns serialized data, so one should change:

add_post_meta($id, $key, $value);

to

add_post_meta($id, $key, maybe_unserialize(stripslashes($value)));

Works for me.

Best regards

Marcin

May 5, 2012 at 4:45 pm #58051

Paul

Hello,

same problem here.

2 months for solving this issue is too much guyz.

I had to make two fixes so far.
First, the same as Marcin.
Second, in sitepress.class.php, in the "update_post_meta" function hook, lines 2973-2978 :

if($original_id == $object_id){
  foreach($translations as $t){
    if(!$t->original){                                
      update_post_meta($t->element_id, $meta_key, maybe_unserialize($_meta_value) );    
    }
  }
}

I had to maybe_unserialize the meta_value before adding it to the translations/duplicate to prevent double serialization.

I hope this will be useful for some of us.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘[Closed] Duplicate post function for a custom post type generates invalid meta data’ is closed to new replies.