• Hi,
    I’ve created this function in order to make this plugin work with WPML.

    Add this function to the Post_Type_Switcher Class:
    /* WPML Support (switch more post translations post type + handles wp_icl_translations)*/
    public function WPML_Support( $post_id, $newPostType ) {

    global $wpdb;

    $myrows = $wpdb->get_results( “SELECT trid FROM {$wpdb->prefix}icl_translations WHERE element_id=” . $post_id );
    $myTrid = $myrows[0]->trid;

    // if Trid exists.
    if ($myTrid) {
    // Update wp_icl_translations table
    $wpdb->update(
    $wpdb->prefix.’icl_translations’,
    array(
    ‘element_type’ => ‘post_’ . $newPostType,
    ),
    array( ‘trid’ => $myTrid )
    );

    // Update all post types of other translations.
    $myrows = $wpdb->get_results( “SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=” . $myTrid );
    foreach($myrows as $row) :
    $wpdb->update(
    $wpdb->prefix.’posts’,
    array(
    ‘post_type’ => $newPostType,
    ),
    array( ‘ID’ => $row->element_id )
    );
    endforeach;
    }

    }

    Search for:

    // Update post type
    $data[‘post_type’] = $post_type;

    And change to:
    // Update post type
    $data[‘post_type’] = $post_type;

    // WPML_Support
    $this->WPML_Support( $post_id, $post_type );

  • The topic ‘WPML Support’ is closed to new replies.