This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Our next available supporter will start replying to tickets in about 11.53 hours from now. Thank you for your understanding.

This thread is resolved. Here is a description of the problem and solution.

Problem: The "Options Page" of the ACF is not copying the fields to the secondary languages.

Solution: The customer solved the problem by creating a custom code. You can see the link below.

Please note that we have not tested this custom code and for this reason, we can not guarantee that this will work for you.

Relevant Documentation: https://wpml.org/documentation/plugins-compatibility/translate-sites-built-with-acf/ https://wpml.org/forums/topic/acf-pro-options-page-synced-fields/#post-1190105

Tagged: 

This topic contains 12 replies, has 5 voices.

Last updated by andrnimm 1 year, 4 months ago.

Assigned support staff: Bruno.

Author Posts
January 13, 2017 at 8:24 am #1181340

stephanR

Hi,

I am using wordpress 4.7, wpml 3.6.2 and acfml 0.3 and acf pro 5.5.2

I am trying to sync option page fields across languages. For that I added them to wpml-config.xml like that:
"<custom-field action="copy">footer-button_link</custom-field>
<custom-field action="copy">_footer-button_link</custom-field>"

But these fields do not get copied. This issue seems related to https://wpml.org/forums/topic/acf-pro-options-page-compatibility/

January 13, 2017 at 7:27 pm #1181986

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us.

Are you using the full wpml-config.xml code? Please see below an example:

<wpml-config>
	<custom-fields>
		<custom-field action="copy">button_link</custom-field>
		<custom-field action="copy">_button_link</custom-field>
	</custom-fields>
</wpml-config>

Also, did you add this wpml-config.xml file into your theme folder? Is the custom field name correct? You can see this on the page WPML > Translation Management > Multilingual Content Setup > Custom Field Translation.

Thank you.

January 16, 2017 at 9:24 am #1182698

stephanR

Hi,

Yes to all your question:
The xml looks like this:
[php]
<wpml-config>
<custom-fields>
<custom-field action="copy">footer-button_link</custom-field>
<custom-field action="copy">_footer-button_link</custom-field>
</custom-fields>
</wpml-config>

The custom field name is also correct and the file is in the correct folder.

January 16, 2017 at 5:39 pm #1183262

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi,

Please as a test, could you disable all non-WPML plugins (keep the ACFML and ACF) and see if the problem persists?

Please, what is the version of WPML and WP are you using? I would like to know more about your installation. Can you please provide your WPML Debug information in the debug field below? http://wpml.org/faq/provide-debug-information-faster-support/

Thank you.

January 20, 2017 at 2:05 pm #1187068

stephanR

I disabled all plugins, Problem still there.
As stated above I use wordpress 4.7, wpml 3.6.2 and acfml 0.3 and acf pro 5.5.2

January 20, 2017 at 9:22 pm #1187432

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi,

Thanks for the debug information.

I need to request temporary access (wp-admin and FTP) to your site - preferably to a test site where the problem has been replicated if possible - in order to be of better help.

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

*** Please let me know exactly what steps should I follow to see the problem.

*** Note: Please make a full backup of your site.

Privacy and Security when Providing Debug Information for Support: https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Thank you.

January 23, 2017 at 7:48 am #1187945

stephanR

The Website is a local development site, so giving you any credentials is not possible.

January 23, 2017 at 9:36 pm #1188795

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Please, could you publish the site so I can check?

Or if you prefer, could you create a copy of your site with Duplicator plugin and upload it to some server like Dropbox or Google Drive and send me the link for me to download and test in my testing environment?

Note that this may be a configuration problem or compatibility issue with your theme or other plugin. I tested this in my testing environment with the basic plugins and with the default theme and this worked properly - so I requested the credentials, as it does not seem to be a bug.

Your next answer will be private.

Thank you.

January 25, 2017 at 8:07 am #1190105

stephanR

We solved the issue by manually copying the the fields on save_post. ACF groups which should be translated have a 'translated' in their name:

add_action('acf/save_post',  __NAMESPACE__ . '\\sync_custom_field', 11);
function sync_custom_field ( $current_post_id ) {
    $post_ids = [];

    // Sync option page fields
    if (($current_post_id == 'options') || ($current_post_id == 'options_fr') || ($current_post_id == 'options_en')) { 
        $post_ids['de'] = 'options';
        $post_ids['en'] = 'options_en';
        $post_ids['fr'] = 'options_fr';
    

        // Get options page field groups set to sync
        $acf_field_groups = acf_get_field_groups();    
        foreach ($acf_field_groups as $group) {
            // Test if group should be synced
            $acf_group_slug = \Weisang\Tools\slugify($group['title']);
            if ( !strpos($acf_group_slug, 'translated') ) {

                // Get fields and sync them
                $acf_group_fields = acf_get_fields($group['ID']);

                foreach ($acf_group_fields as $field) {
                    if ($field['type'] == 'file') {
                        $value = get_field( $field['name'], $current_post_id, false);

                        foreach ($post_ids as $lang_id) {
                            if ( $current_post_id != $lang_id ) { update_field( $field['name'], $value, $lang_id); }     
                        }
                    } else {
                        $value = get_field( $field['name'], $current_post_id);  

                        foreach ($post_ids as $lang_id) {
                            if ( $current_post_id != $lang_id ) { update_field( $field['name'], $value, $lang_id); }     
                        }                     
                    }
                }
            }        
        }
    }     
}

This syncs between all present languages.

October 19, 2017 at 12:05 pm #1405848

andreK-7
$acf_group_slug = \Weisang\Tools\slugify($group['title']);

Could you probably give me a link to this function/class named slugify?

Others than that: I tried to streamline the function a bit, so that it still works, if later on another language will be added. Seems to work 😉


/* sync ACF options */
add_action('acf/save_post',  __NAMESPACE__ . '\\sync_custom_field', 11);
function sync_custom_field ( $current_post_id ) {
    $post_ids = [];
	
	$langs = icl_get_languages('skip_missing=0&orderby=KEY&order=DIR&link_empty_to=str');
	$wpml_options = get_option( 'icl_sitepress_settings' );
	$default_lang = $wpml_options['default_language'];
	
	$option_pages = array();
	foreach ($langs as $language) {
		 if($language['language_code'] === $default_lang){
			 $post_ids[$default_lang] = 'options';
			 $option_pages[] =  'options';
		 } else {
			$post_ids[$language['language_code']] = 'options_'.$language['language_code'];
			$option_pages[] =  'options_'.$language['language_code'];;
		 }
	}
	
    // Sync option page fields
    if (in_array($current_post_id,$option_pages)) { 
 
        // Get options page field groups set to sync
        $acf_field_groups = acf_get_field_groups(); 
		
        foreach ($acf_field_groups as $group) {
			
			$field_string .= $group['title'].', ';
            // Test if group should be synced
			//$acf_group_slug = \Weisang\Tools\slugify($group['title']);
            if ( !strpos($group['title'], 'translated') ) {
 
                // Get fields and sync them
                $acf_group_fields = acf_get_fields($group['ID']);
 
                foreach ($acf_group_fields as $field) {
                    if ($field['type'] == 'file') {
                        $value = get_field( $field['name'], $current_post_id, false);
 
                        foreach ($post_ids as $lang_id) {
                            if ( $current_post_id != $lang_id ) { update_field( $field['name'], $value, $lang_id); }     
                        }
                    } else {
                        $value = get_field( $field['name'], $current_post_id);  
 
                        foreach ($post_ids as $lang_id) {
                            if ( $current_post_id != $lang_id ) { update_field( $field['name'], $value, $lang_id); }     
                        }                     
                    }
                }
            }
				
        }
    }  
}

Thanks for bringing this handy solution up, greetings from germany!

May 19, 2018 at 9:48 pm #2195730

andrnimm

Wow, this function works. Great work, andreK-7 and stephan R. It doesn't seem to copy over image fields (at least those returning a URL) but it's already a big help. THANK YOU.

Moderators: This function can be adapted for the ACFML plugin, it would be best to get Konrad Karpieszuk @konrad-k here to try it. Site options are a key part of ACF and they obviously need to be translated for sites to work.

May 29, 2018 at 7:16 am #2243167

Konrad Karpieszuk
Supporter

Languages: English (English )

Timezone: Europe/Rome (GMT+02:00)

Thanks AndreK-7 for proposed solution and andrnimm for pinging me by email about this 🙂

Could you verify if I understand well? It just creates options_{language code} for each language, right?

Do you need to add anything in site templates to obtain those translated values?

Also, I understand it just copies the values between languages, yes? There is no way yet to translate them?

May 29, 2018 at 8:02 pm #2248144

andrnimm

Konrad,
I spoke too soon, you're right. Thanks for checking it out. This solution doesn't allow translating the values.

For example, a site with sitewide options like "company description" in the footer would need that translated in every language.

It seems that a template call for get_field( "sitewide_option_1", "options" ) would need to be run through a check to get it in the current language, like everything else.

My workaround has been to put all sitewide options as custom fields of the home page, currently.

Please let me know if you would like me to dig through anything specific about ACF or WPML code to help enable this. I'm on deadline for a large project right now, so i can't go on a huge hunting expedition with it, but if i can help in increments of an hour or two, i am happy to help.