- Trạng thái
- Đã được giải quyết bởi nhà phát triển
- Đã giải quyết trong
- BetterDocs 4.2.3
- Plugin/giao diện liên quan
- BetterDocs
- Thẻ chủ đề
- Compatibility
Tổng quan về lỗi
Khi sử dụng BetterDocs với WPML, bạn có thể gặp phải sự cố sau: việc sắp xếp lại Docs thông qua giao diện kéo và thả của BetterDocs khiến việc gán danh mục bị mất đồng bộ ở các ngôn ngữ phụ. Do đó, Docs có thể bị gán sai vào các danh mục từ ngôn ngữ khác và thứ tự mới có thể không được phản ánh trên các bản dịch.
Giải pháp tạm thời
Vui lòng đảm bảo bạn đã sao lưu toàn bộ trang web trước khi tiếp tục.
- Mở tệp …wp-content/plugins/betterdocs/includes/Core/PostType.php.
- Tìm dòng 599.
- Thay thế:
if ( update_term_meta( $term_id, '_docs_order', $docs_ordering_data ) ) { wp_send_json_success( __( 'Successfully updated.', 'betterdocs' ) ); } - Bằng:
if ( update_term_meta( $term_id, '_docs_order', $docs_ordering_data ) ) { // WPML Integration: Sync taxonomies after order change if ( class_exists( 'SitePress' ) && class_exists( 'WPML_Term_Translation_Utils' ) ) { $docs_array = isset( $_POST['docs_ordering_data'] ) && is_array( $_POST['docs_ordering_data'] ) ? array_map( 'intval', $_POST['docs_ordering_data'] ) : explode( ',', $docs_ordering_data ); $this->wpml_sync_posts_taxonomies( $docs_array ); } wp_send_json_success( __( 'Successfully updated.', 'betterdocs' ) ); } - Ở cuối tệp này, trước
}cuối cùng (khoảng dòng 1130). - Thêm hàm trợ giúp này:
/** * WPML Integration: Sync post taxonomies across translations * @param array $post_ids Array of post IDs to sync */ private function wpml_sync_posts_taxonomies( $post_ids ) { global $sitepress; if ( ! $sitepress || empty( $post_ids ) ) return; $sync = new WPML_Term_Translation_Utils( $sitepress ); foreach ( $post_ids as $post_id ) { $trid = $sitepress->get_element_trid( $post_id, 'post_docs' ); if ( ! $trid ) continue; $translations = $sitepress->get_element_translations( $trid, 'post_docs' ); $original_id = $post_id; foreach ( $translations as $translation ) { if ( isset( $translation->original ) && $translation->original == 1 ) { $original_id = $translation->element_id; break; } } foreach ( $sitepress->get_active_languages() as $lang => $details ) { $sync->sync_terms( $original_id, $lang ); } } }