Created
June 10, 2020 19:02
-
-
Save theRealRizeo/661364eecd89ba9ee30d229f445f2926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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