Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save theRealRizeo/661364eecd89ba9ee30d229f445f2926 to your computer and use it in GitHub Desktop.
Save theRealRizeo/661364eecd89ba9ee30d229f445f2926 to your computer and use it in GitHub Desktop.
<?php
function copy_post( $post_id ) {
if ( function_exists( 'PLL' ) ) {
$model = PLL()->model;
$post = get_post( $post_id );
$post->ID = null;
$translations = pll_get_post_translations( $post_id );
foreach ( $model->get_languages_list() as $language ) {
$tr_id = pll_get_post( $post_id, $language );
if ( empty( $tr_id ) ) {
$tr_id = wp_insert_post( $post );
pll_set_post_language( $tr_id, $language );
pll_save_post_translations( $translations );
PLL()->sync->post_metas->copy( $post_id, $tr_id, $language );
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment