WPML
ステータス
解決済み

問題の概要

一部のACFフィールドタイプでは、コンテンツを適切に複製することができません。

回避策

この投稿の「詳細な説明」セクションに記載されているフィールドのいずれかを使用している場合、複製が正しく機能するように、テーマのfunctions.phpファイルにこのスニペットを追加してください。

function wpml_fix_acf_duplication( $value_to_filter, $target_language, $meta_data ) {
  // Field names should be placed into following array.
  $fields = array(
     'test_taxonomy' => 'some_taxonomy_name',
     'test_image' => 'attachment',
     'test_file' => 'attachment',
     'test_gallery' => 'attachment',
     'test_post_object' => 'post',
     'test_page_link' => 'page'
  );

  if ( array_key_exists( $meta_data['key'], $fields ) ) {
		$value = maybe_unserialize( $value_to_filter );

		if ( is_array( $value ) ) {
			// If custom field value contain array of IDs to translate, usually used for gallery and taxonomy field types.
			$translated_ids = array();

			foreach ( $value as $v ) {
				$translated_ids[] = apply_filters( 'wpml_object_id', $v, $fields[ $meta_data['key'] ], true, $target_language );
			}

			return maybe_serialize( $translated_ids );
		} else {
			// If custom field value contain single ID to translate, usually used for image and file field types.
			$translated_id = apply_filters( 'wpml_object_id', $value, $fields[ $meta_data['key'] ], true, $target_language );

			return $translated_id;
		}
	}

	return $value_to_filter;
}
add_filter( 'wpml_duplicate_generic_string', 'wpml_fix_acf_duplication', 999, 3 );

注意:配列のkey => valueペアを適切な値に置き換えてください。

次の画像の例に示すように、「test_taxonomy」、「test_image」、「test_file」などのキーをサイトのフィールド名に置き換えます。 画像01
同様に、「some_taxonomy_name」、「attachment」、post、pageなどのを置き換えます。
これはIDが属する要素のタイプです。post、page、attachment、{custom post type key}、nav_menu、nav_menu_item、category、post_tag、{custom taxonomy key}のいずれかを指定できます。

詳細については、こちらのフックのドキュメントを確認してください。

すべての既知の問題 →