WPML translation sync
-
Hello,
There seems to be a hitch with the WPML integration.
I do have two languages activated (French and English) on my website.
When I move a page in my hierarchy, the
menu_order
value is saved in both entities (FR and EN), but thepost_parent
is only persisted in the entity I moved and not the translation.I edited the WPML integration for my needs but I would like to know if someone else has this issue.
Here is the modified version of the WPML integration.
\NestedPages\Entities\PluginIntegration\WPML::syncPostOrder
public function syncPostOrder($posts, $post_parent = 0) { if ( $this->settings['sync_page_ordering'] !== 1 ) return; global $wpdb; if ( !is_array($posts) ) return; foreach ( $posts as $order => $post ) : $translations = $this->getAllTranslations($post['id']); foreach ( $translations as $lang_code => $post_info ) : $translation_post_id = $post_info->element_id; $translated_parent = $this->getAllTranslations($post_parent)[$lang_code]->element_id; $query = "UPDATE $wpdb->posts SET menu_order = '$order', post_parent = '$translated_parent' WHERE ID = '$translation_post_id'"; $wpdb->query( $query ); endforeach; if (isset($post['children'])) : $this->syncPostOrder($post['children'], $post['id']); endif; endforeach; }
The only missing thing is to get the translated
post_parent
and to save it along with themenu_order
just like it’s done in\NestedPages\Entities\Post\PostUpdateRepository::updateOrder
Please let me know if I should contribute this.
Timothée
- The topic ‘WPML translation sync’ is closed to new replies.