skip to Main Content

I created a custom field (using ACF Plugin) called "my_custom_field". Then I use this code to get the value for that custom field which works fine:

echo $output = get_post_meta($data['post_id'], "my_custom_field", true);

My site have two languages (french and spanish). I use WPML for translations.

Problem is that the $output always shows the value for the default language (french) even if the $output is loaded and printed in an "spanish" page.

I guess that I need to add something else in my code to detect the language and show the $output accordingly.

2

Answers


  1. Chosen as BEST ANSWER

    this fixed the problem:

    $wpml_post_id = icl_object_id($data['post_id'], 'page', false,ICL_LANGUAGE_CODE);
    echo $output = get_post_meta($wpml_post_id, "my_custom_field", true);
    

  2. To make the ACF field translatable for WPML you need to install the ACFML plugin that you can download from your account on the WPML website.

    With this plugin, you can make ACF fields translatable. More you can read inside official documentation: https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search