Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syncing custom fields between 2 languages (with WPML)

I'm using WPML (Wordpress multilanguage plugin) with custom post and fields (with Advanced Custom Fields plugin) and I have this "issue": I've a custom post with a custom field (text), I enter text in the field and save. Now I go to the translated post and see that the same custom field is empty. Then the fields ar not synched. Notice that instead the Tag field is well synched between the languages. Someone can help? Thanks

like image 410
Fred K Avatar asked Dec 10 '25 00:12

Fred K


1 Answers

I don´t think the saved value of a custom field is synced by default. Only the name of the variable etc.

So if you have a custom field and wan´t it to have the same value on all languages, simply don´t add that custom field to other languages. Just have it on the main language.

Then in the template you can use this, to allways get the value from main language:

<?php the_field('fieldname',lang_page_original_id($post->ID));?>

Then add this to functions.php

function lang_page_original_id($id){
    if(function_exists('icl_object_id')) {
    return icl_object_id($id,'page', false, "MAIN LANGUAGE CODE EX: SV");
    } else {
        return $id;
    }
}
like image 110
Turbojohan Avatar answered Dec 12 '25 00:12

Turbojohan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!