In WordPress I'm using the CMB2 plugins (framework for creating metabox and metafield) and WPML Media (WPML add-on avoids saving the same attachment for each language, creating translations of: title, alt, description and caption, to that only attachment); I'm creating a metafield like file_list
that saves attachments in an array (id => url)
like this:
$cmb = new_cmb2_box( array(
'id' => 'benny_metabox_photo',
'title' => esc_html__( 'My Photo Metabox', 'mydomain' ),
'object_types' => array( 'post' )
) );
$cmb->add_field( array(
'name' => esc_html__( 'My Photo', 'mydomain' ),
'id' => 'benny-file-list',
'type' => 'file_list',
'preview_size' => array( 100, 100 ),
'text' => array(
'add_upload_files_text' => esc_html__( 'Add Photos', 'mydomain' ),
'remove_image_text' => esc_html__( 'Remove Photo', 'mydomain' ),
'file_text' => esc_html__( 'Photo:', 'mydomain' ),
'file_download_text' => esc_html__( 'Download', 'mydomain' ),
'remove_text' => esc_html__( 'Remove', 'mydomain' )
)
) );
So, when I create a post in the main language set in WPML everything works correctly. But when I create translations and insert attachments in the file_list
field, the ids always refer to attachments in the main language and not to its translations, so in the frontend - when you display the site in the languages translated - the title, alt, description and caption for the images uploaded in the file_list
field are in the main language. How could I do to view their translations and not the main language?