• Resolved joedev91

    (@joedev91)


    Hi

    I’m using the latest version of this plugin with WP 4.6.1. In a duplicated post meta keys are duplicated, I have 2 metas with the same name.

    If you need more information let me know.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter joedev91

    (@joedev91)

    I think by default some metas are created with post creation and you are using add_post_meta instead of update_post_meta so if the meta exist, for some reason, this meta will be duplicated.

    I checked update_post_meta docs and this method will update the meta if was found and if not will be created. Well if you put add_post_meta instead update_post_meta for some reason let me know.

    I changed that and it works for me, no more duplicated metas in my new cloned posts.

        //Add the source post meta to the destination post
        foreach ( $data as $key => $values) {
    
           foreach ($values as $value) {
    
               update_post_meta( $post_id, $key, $value );
    
            }
    
        }
        
        //Copy the meta data collected from the sourse post to the new post
      	foreach ($meta_values as $key => $values) {
    
           foreach ($values as $value) {
                //If the data is serialised we need to unserialise it before adding or WordPress will serialise the serialised data
                //...which is bad
                if(is_serialized($value)){
                 
                    update_post_meta( $post_id, $key, unserialize($value));
    
                }else{
    
                    update_post_meta( $post_id, $key, $value );
    
                }
               
            }
    
        }

    Thanks.

    • This reply was modified 9 years, 7 months ago by joedev91.
    Plugin Author MagicStick

    (@magicstick)

    Once again thanks joe. Dunno why I had that set at add_ rather than update_. I’m a silly man.

    Plugin Author MagicStick

    (@magicstick)

    Fixed in 0.9.3 🙂

    Thread Starter joedev91

    (@joedev91)

    No problem!

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

The topic ‘Duplicted metas’ is closed to new replies.