- ステータス
- 開発者により解決済み
- 解決されたバージョン
- BetterDocs 4.2.3
- 関連するプラグイン/テーマ
- BetterDocs
- トピックタグ
- Compatibility
問題の概要
WPMLでBetterDocsを使用すると、次の問題が発生する場合があります。BetterDocsのドラッグ&ドロップUIでDocsの並べ替えを行うと、カテゴリーの割り当てがセカンダリ言語で同期されなくなります。
その結果、Docsが他の言語のカテゴリーに誤って割り当てられたり、新しい順序が翻訳に反映されなかったりする場合があります。
回避策
続行する前に、必ずサイトの完全なバックアップを取得してください。
- …wp-content/plugins/betterdocs/includes/Core/PostType.phpファイルを開きます。
- 599行目を探します。
- 次を:
if ( update_term_meta( $term_id, '_docs_order', $docs_ordering_data ) ) { wp_send_json_success( __( 'Successfully updated.', 'betterdocs' ) ); } - 次のように置き換えます:
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' ) ); } - 同じファイルの最後、最後の
}の前(1130行目付近)に移動します。 - 次のヘルパー関数を追加します:
/** * 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 ); } } }