WordPress.org

Ready to get started?Download WordPress

Forums

Post Type Switcher bug with WPML (5 posts)

  1. Ov3rfly
    Member
    Posted 2 years ago #

    If WPML Multilingual CMS plugin (more or less the standard plugin for multi-language WordPress sites) is installed, Post Type Switcher does not work as expected.

    The post_type is changed in 'wp_posts' table but the post does not show up any more in admin-panel, not as old and not as new type.

    Fix: When changing the post type, add a check if WPML is installed and if yes, adjust the type in a second table 'wp_icl_translations' as explained here:

    if ( function_exists('icl_object_id') ) {
       // adjust field 'element_type' in table 'wp_icl_translations'
       // from 'post_OLDNAME' to 'post_NEWNAME'
       // the post_id you look for is in column: 'element_id'
    }

    More about WPML-API here.

    http://wordpress.org/extend/plugins/post-type-switcher/
    http://wpml.org/

  2. AmirHelzer
    Member
    Posted 2 years ago #

    I'm responsible for WPML.

    We're offering free WPML accounts for fellow plugin authors. If you're the author and want to work on this compatibility issue with us, please visit this page:
    http://wpml.org/documentation/theme-compatibility/go-global-program/

  3. nowton
    Member
    Posted 2 years ago #

    I just had this happen to me on my build location. How can I retrieve the missing posts?

  4. fanchyfanch
    Member
    Posted 2 years ago #

    Hi,

    Thanks for the tip but don't you have the complete correct code to put exactly so the WPML plugin works properly ?

  5. fanchyfanch
    Member
    Posted 2 years ago #

    OK, it goes like this for those who search for a solution :


    // in case of using the WPML plugin
    if(function_exists('icl_object_id')){
    // adjust field 'element_type' in table 'wp_icl_translations'
    // from 'post_OLDNAME' to 'post_NEWNAME'
    // the post_id you look for is in column: 'element_id'

    if($post->post_type == 'revision'){
    if(is_array($post->ancestors)){
    $ID = $post->ancestors[0];
    }
    }else{
    $ID = $post->ID;
    }

    $wpdb->update("{$wpdb->prefix}icl_translations", array('element_type' => 'post_' . $new_post_type_object->name), array('element_id' => $ID));
    }

Topic Closed

This topic has been closed to new replies.

About this Topic