Skip to content

Instantly share code, notes, and snippets.

@Inzman
Created April 5, 2018 10:03
Show Gist options
  • Select an option

  • Save Inzman/37e64ea7d42a3dd13c18a180577b41b3 to your computer and use it in GitHub Desktop.

Select an option

Save Inzman/37e64ea7d42a3dd13c18a180577b41b3 to your computer and use it in GitHub Desktop.
Update WPML translated pages with original language content
<?php
if(is_user_logged_in()){
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'publish',
'suppress_filters' => false
);
$pages = get_posts($args);
echo '<table>';
foreach($pages as $nr => $page){ //pre($page);
$post_content_et = $page->post_content;
global $sitepress;
$trid = $sitepress->get_element_trid($page->ID, 'post_' . $page->post_type);
$translations = $sitepress->get_element_translations($trid, 'post_' . $page->post_type);
ksort($translations);
echo '<tr>';
echo '<td style="padding:10px;">'.($nr+1).'</td>';
echo '<td style="padding:10px;">'.$page->post_title.'</td>';
foreach($translations as $k => $v){
$translation_id = $v->element_id;
$is_to_be_updated = $v->original ? false : true;
echo '<td style="padding:10px;">'.$k.' :: '.$translation_id.' :: '.$is_to_be_updated.'</td>';
if($is_to_be_updated){
$my_post = array(
'ID' => $translation_id,
'post_content' => $post_content_et
//'post_excerpt' => ''
);
//wp_update_post($my_post);
}
}
echo '</tr>';
}
echo '</table>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment