WPML
Stato
Risolto

Panoramica del problema

Per alcuni tipi di campo ACF non è possibile duplicare correttamente il contenuto.

Soluzione alternativa

Se stai utilizzando uno dei campi elencati nella sezione Descrizione completa di questo articolo, devi aggiungere questo snippet al file functions.php del tuo tema affinché la duplicazione funzioni correttamente.

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 );

NOTA: devi sostituire le coppie chiave => valore dell’array con i valori appropriati.

Sostituisci le chiavi come: ‘test_taxonomy’, ‘test_image’, ‘test_file’, ecc. con i nomi dei campi del tuo sito, come mostrato nell’immagine di esempio seguente. image01
Sostituisci di conseguenza i valori come: ‘some_taxonomy_name’, ‘attachment’, post, page, ecc.
Questo è il tipo di elemento a cui appartiene l’ID. Può essere post, page, attachment, {custom post type key}, nav_menu, nav_menu_item, category, post_tag, {custom taxonomy key}

Per maggiori informazioni, consulta la nostra documentazione sugli hook qui.

Tutti i problemi noti →