- ステータス
- 未解決
- 報告対象
- Advanced Custom Fields Multilingual 2.1.5
- 関連するプラグイン/テーマ
- Advanced Custom Fields (ACF)
- トピックタグ
- Compatibility
問題の概要
WPMLでAdvanced Custom Fields (ACF)を使用する場合、セカンダリ言語で条件付きロジックが正しく機能しない問題が発生する可能性があります。これは、条件付きロジックが、タクソノミーや投稿オブジェクトフィールドなどの、オブジェクトベースまたはタームベースの参照を使用するフィールドに依存している場合に発生します。
回避策
続行する前に、必ず完全なサイトバックアップを取得してください。
- テーマのfunctions.phpファイルに以下のコードを追加してください。
/** * WPML Workaround for compsupp-wpmltriage-3649 */ add_action( 'init', function() { if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { add_filter( 'acf/load_field', function ( $field ) { if ( empty( $field['conditional_logic'] ) || ! is_array( $field['conditional_logic'] ) ) { return $field; } foreach ( $field['conditional_logic'] as $group_index => $rules ) { if ( ! is_array( $rules ) ) { continue; } foreach ( $rules as $rule_index => $rule ) { if ( isset( $rule['field'], $rule['value'] ) && is_numeric( $rule['value'] ) ) { // Fetch the parent field $parent_field = acf_get_field( $rule['field'] ); if ( ! isset( $parent_field['type'] ) ) { continue; } if ( $parent_field['type'] === 'taxonomy' ) { $rule['value'] = apply_filters( 'wpml_object_id', $rule['value'], $parent_field['taxonomy'], true ); } elseif ( $parent_field['type'] === 'post_object' ) { $post_types = $parent_field['post_type'] ?? ''; // can be multiple if ( is_array( $post_types ) ) { foreach ( $post_types as $post_type ) { $translated_id = apply_filters( 'wpml_object_id', $rule['value'], $post_type, true ); if ( $translated_id && $translated_id !== $rule['value'] ) { $rule['value'] = $translated_id; break; } } } else { $rule['value'] = apply_filters( 'wpml_object_id', $rule['value'], $post_types, true ); } } $field['conditional_logic'][ $group_index ][ $rule_index ] = $rule; } } } return $field; }, 100 ); } } );