Home › Forums › Add-ons › Gallery Field › Gallery field doesn't accept data from other languages › Reply To: Gallery field doesn't accept data from other languages
I’d like to add something odd. Apparently after all this time, the images were added anyway, but not the the editor. Meaning they were somehow tied to the post object, but not the editor of it.
Here is my final code.
global $sitepress;
$jargs = array(
'post_type' => 'ettevote',
'posts_per_page' => -1,
'post_status' => 'publish'
);
$allposts = array();
$loop = new WP_Query( $jargs );
while ( $loop->have_posts() ) : $loop->the_post();
$wpid = get_the_ID();
$engposts = get_fields($wpid);
$orcontent = get_the_content();
$wpml_element_type = apply_filters( 'wpml_element_type', 'ettevote' );
$t_post_id = $sitepress->get_element_trid( $wpid, 'post_ettevote' );
$translations = $sitepress->get_element_translations($t_post_id , 'post_ettevote', false, true);
$original_post_language_info = apply_filters( 'wpml_element_language_details', null, $get_language_args );
$aid = get_the_author_meta('ID');
$region_id = get_user_meta($aid, 'user_region', true);
$engthumbnailID = get_post_thumbnail_id($wpid);
$postids = array();
foreach($translations as $langs){
array_push($postids, $wpid, $langs->element_id);
if($langs->element_id){
$my_post = array(
'ID' => $langs->element_id,
'post_author' => $aid,
);
set_post_thumbnail( $langs->element_id, $engthumbnailID );
$newpost_id = wp_update_post($my_post);
$set_language_args = array(
'element_id' => $newpost_id,
'element_type' => $wpml_element_type,
'trid' => $t_post_id,
'language_code' => $langs->language_code,
'source_language_code' => $original_post_language_info->language_code
);
do_action( 'wpml_set_element_language_details', $set_language_args );
//update ettevote fields
update_field('galerii', $engposts['galerii'], $langs->element_id);
update_field('video', $engposts['video'], $langs->element_id);
update_field('country', $engposts['country'], $langs->element_id);
update_field('city', $engposts['city'], $langs->element_id);
update_field('street', $engposts['street'], $langs->element_id);
update_field('house', $engposts['house'], $langs->element_id);
update_field('aadress', $engposts['aadress'], $langs->element_id);
}
else{
continue;
}
endwhile;
Maybe it helps someone in the future
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.