Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

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.

This topic contains 10 replies, has 2 voices.

Last updated by Shekhar Bhandari 7 months ago.

Assigned support staff: Shekhar Bhandari.

Author Posts
May 13, 2019 at 7:32 pm

dominikF-5

I am trying to translate ACF Fields inside a default Options Page.

I expected to save different values on different languages.

Instead, I always get the latest value i have saved (independent on the current or default language)

As mentioned here (https://wpml.org/forums/topic/acf-options-pages-are-not-duped-translated/) i also tried to make the acf-field-group translatable and copied the field group to the other language but it didn't help.

But i rather would prefer to not translate ACF Field Groups and just have the same behaviour as if we are on a custom post type.

Versions:
Wordpres 5.2
WPML 4.2.6
String Translation 2.10.4
ACFML 1.3 (also tried 1.1 but didn't work either)

May 14, 2019 at 5:43 am #3803753

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Thanks for getting in touch, I can definitely help you out with this.

Here’s what you’ll need to get started:

1) It does not need to translate the fields group, you can set it as "Don't translate" if you don't want the interface to be translated.

2) You are using the following code to add the options page

function my_acf_init() {
    $args = array(
        'page_title' => 'Theme-Optionen',
        'post_id' => 'theme-options'
    );
    acf_add_options_page( $args );
}

add_action('acf/init', 'my_acf_init');

I replaced it with the one suggested on the official documenation and it solved the issue for me on my localhost, so could you please try the same and share us the results?
hidden link

if( function_exists('acf_add_options_page') ) {

    acf_add_options_page(array(
        'page_title' => 'Theme-Optionen',
        'menu_title' => 'Theme-Optionen',
        'menu_slug' => 'theme-general-settings',
        'capability' => 'edit_posts',
        'redirect' => false
    ));
}

Let me know if this helps.

Thanks

May 14, 2019 at 6:45 am #3803993

dominikF-5

Dear Shekhar Bhandari,

thank you for your quick reply.

Your described solution indeed fixes my problem.

But the main problem here was my definition of a 'post_id' in the definition of the acf_add_options_page args array.
If i remove my

'post_id' => 'theme-options'

from the array, it fixes the problem.

Therefore my question here is: Why does providing a custom "post_id" destroy the multilingual functionality?

Even more so - Why does providing the default value "options" as "post_id" (from the ACF acf_add_options_page documentation page) destroy the multilingual funtionality as well?

Only when i remove the key-value pair for "post_id" from the arguments array the multilingual funtionality works.

May 14, 2019 at 6:54 am #3804059

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

 Why does providing a custom "post_id" destroy the multilingual functionality?

I am not exactly sure about this at the moment, I will need to run a few tests before providing answers on this.

In order to perform further tests, I would need your little help, could you please provide feedback on the following?

- Why are you adding custom post id to the theme options args? I wanted to know how it's useful.

- Is there any documentation which has explained the way to add the post-id in options array?

Look forward to receiving your answers so we can get to the bottom of this issue.

Thanks

May 14, 2019 at 7:22 am #3804259

dominikF-5

- Why are you adding custom post id to the theme options args? I wanted to know how it's useful.

In some cases we create multiple options pages due to how we structure the fields in the backend.

The available functions to structure the fields inside an options page like creating sub-pages and tabs are not always enough for the amount of fields we have to create.

Or the type of field data requires two separate options-pages to comply with given data-structure.

Example would be like 1 options page for "Events" with like 6 sub-pages and 50 fields inside them and a 2 options page for "Locations" and the same amount of sub-pages and fields.

To retrieve the data from 2 different options pages we have to specifiy a custom post_id, otherwise i wouldn't know how to retrieve the data from the fields inside one of these options pages with "get_field".

Otherwise the possibility to set a custom post_id would be rather useless in my opinion.

For me, an options page is a global area to define settings for the whole page or in this example as specific part (Events or Locations) of the whole page.

But these global settings can change depending on the given language.

- Is there any documentation which has explained the way to add the post-id in options array?

I think you misunderstood me here.
My "options array" is just a variable where the arguments are placed for the acf_add_options_page function.

I don't like placing larger associative arrays inside a function call. Instead i prefer to define it as a separate variable and just pass the variable to the function.

therefore this

    acf_add_options_page(array(
        'page_title' => 'Theme-Optionen',
        'menu_title' => 'Theme-Optionen',
        'menu_slug' => 'theme-general-settings',
        'capability' => 'edit_posts',
        'redirect' => false
    ));

and this

    $args = array(
        'page_title' => 'Theme-Optionen',
        'menu_title' => 'Theme-Optionen',
        'menu_slug' => 'theme-general-settings',
        'capability' => 'edit_posts',
        'redirect' => false
    );
    acf_add_options_page($args);

are the same.

Its just a Code-Style of mine.

May 14, 2019 at 7:47 am #3804405

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Firstly, thank you very much for the explanation. 🙂

I am sorry I wasn't aware of the post_id arguments available for the acf_add_options_page function. I just visited the following link and can see the available arguments which have mentioned about the post_id.
hidden link

I searched for the usage in our documentation/sites/internal documents and I found a comment from the client here with the solution, https://wpml.org/2019/05/recent-and-upcoming-changes-in-how-to-translate-acf-options-pages/ So I tested it and it's working perfectly, so please follow the below steps to fix the issue.

- While adding post_id concat icl_language_code to the options name, so it's different for both languages, an example will be

'post_id' => 'test_'. ICL_LANGUAGE_CODE

- While retrieving use the following code

get_field('first_name', 'test_'. ICL_LANGUAGE_CODE));

Let me know if this helps.

Thanks

May 14, 2019 at 8:05 am #3804595

dominikF-5

Indeed this fixes the problem.

The only other problem this causes is the following:

If i change the post-id to

'theme-options_' . ICL_LANGUAGE_CODE

i therefore "lose" all the already present data in the options page.

How do i "convert" the already present data in the options page with the post-id "theme-options" to "theme-options_de" so i don't have to copy paste the field data?

May 14, 2019 at 8:28 am #3804709

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

I don't think there is an option to convert these fields automatically, so you should manually add the content in the new field or make field name changes in the database.

I am sorry I couldn't be much help here.

Thanks

May 14, 2019 at 8:56 am #3804949

dominikF-5

I wrote a small SQL Script for that problem.

The values for options pages are saved in the wp_options table.

Each field is saved something like <post_id>_<field_name> therefore its not that complicated to update this.

Of course I backuped the DB if something went wrong.

UPDATE wp_options
SET    option_name = replace(option_name, 'theme-options', 'theme-options_de')
WHERE  option_name LIKE '%theme-options%';

After changing the post_id to

'theme-options_' . ICL_LANGUAGE_CODE

the already present data is still there and i just have to copy the other values to the english translation now.

Thank you for your help!

May 14, 2019 at 8:57 am #3804951

dominikF-5

My issue is resolved now. Thank you!

May 14, 2019 at 8:58 am #3804953

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Thank you for sharing the solution. 🙂

I think we can close now.

Kind Regards,
Shekhar