Skip to content

Instantly share code, notes, and snippets.

@TravisBallard
Created September 26, 2012 15:36
Show Gist options
  • Save TravisBallard/3788747 to your computer and use it in GitHub Desktop.
Save TravisBallard/3788747 to your computer and use it in GitHub Desktop.
WPML / WPRobot
/**
* create english version of posts automatically when they are added by wp robot
*
* @param mixed $post_id
* @param mixed $post
*/
function duplicate_wp_robot_imported_posts_for_wpml( $post_id, $post = null )
{
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
global $wpdb;
if( ! isset( $post ) ) $post = get_post( $post_id );
if( $post->post_type == 'post' )
{
$trid = $wpdb->get_var( $wpdb->prepare( 'SELECT translation_id FROM wp_icl_translations WHERE element_type = "post_post" AND element_id = %d', intval( $post_id ) ) );
$q = $wpdb->prepare( 'insert into wp_icl_translations ( `element_type`, `element_id`, `trid`, `language_code`, `source_language_code` ) values( "post_post", "%s", "%s", "en","es" )', $post_id, $trid );
$wpdb->query( $q );
}
}
add_action( 'save_post', 'duplicate_wp_robot_imported_posts_for_wpml', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment