Created
April 5, 2018 10:03
-
-
Save Inzman/37e64ea7d42a3dd13c18a180577b41b3 to your computer and use it in GitHub Desktop.
Update WPML translated pages with original language content
This file contains hidden or 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 | |
| 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