2
votes

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

3

3 Answers

2
votes

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;
    }
}
1
votes

Here are ACF docs: http://www.advancedcustomfields.com/resources/multilingual-custom-fields/

But it doesn't work as well as you may expect. Syncing is only "one way" from original to translated versions. See: https://wordpress.stackexchange.com/questions/181338/fixed-values-for-same-post-translations/214120#214120 for more details.

You will need WPML Multilingual CMS in order to use sync feature.

1
votes

Hi use this in your function.php works 100%:

function sync_field_meta( $post_id, $post, $update ) {

    $post_type = get_post_type($post_id);
    // use this if u have muti custom post type
    $posts_type = array('your_custom_post_type1', 'your_custom_post_type2', 'your_custom_post_type3', 'your_custom_post_type4');

    if( ! in_array($post_type, $posts_type)) return;

    $en = apply_filters( 'wpml_object_id', $post_id, 'any', FALSE, 'en' );
    $fr = apply_filters( 'wpml_object_id', $post_id, 'any', FALSE, 'fr' );

    // your acf key like (field_58136c9dc9963) you can check documention
    $field = get_field('acf_key',$post_id);

    if($en){
        update_field('acf_key',$field,$en);
    }
    if($fr){
        update_field('acf_key',$field,$fr);
    }


}
add_action( 'save_post', 'sync_field_meta', 10, 3 );