Support

Account

Home Forums Add-ons Options Page Using update_field() to save data to a custom field on an options page with wpml

Solving

Using update_field() to save data to a custom field on an options page with wpml

  • Hi,

    I am building a site which has an options page and 6 languages. I am using ACF and WPML. The issue I have is that I need to dynamically save some data into a specific custom field on the options page (I am basically pulling in a social feed). I would normally use:

    update_field( “field_54f862d0af927”, $data, ‘options’ );

    But this unfortunately does not work for multi language as each field id number is different for each language. What are my options here, ideally I would just use something like:

    update_field( “news_hidden_news_data”, $data, ‘options’ );

    But this only seems to update the English field and not any of the other languages. I want to avoid a situation where I am having to hardcode each field id number into the code for each language. For example when you use get_field( “news_hidden_news_data”) it can automatically work out which language is currently selected and pull the correct field, but unfortunately this does not seem to work the other way when trying to add data, what are my options?

    Thanks in advance,

    Dave

  • Hi @quirksmode,

    Thanks for the post.

    Each field group within each language will require a translation of the field group and each field will have a unique name with a prefix containing the WPML language code (en_, fr_)

    You can then target the field using the update_field() like so:

    update_field( LANG_CODE . '_twitter',$data, 'options');

    I hope this helps.

  • Hi.

    I have the same problem. But this does not seem to work (anymore)?

    update_field( LANG_CODE . ‘_twitter’,$data, ‘options’);

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Using update_field() to save data to a custom field on an options page with wpml’ is closed to new replies.